Current File : /home/tradevaly/demo.tradevaly.com.bd/app/Http/Controllers/BuyingSellingController.php |
<?php
namespace App\Http\Controllers;
use App\Models\BuyingSelling;
use App\Models\ProductCategory;
use Illuminate\Http\Request;
use Auth;
class BuyingSellingController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$topCategory = ProductCategory::getTopCategoryList();
$data = BuyingSelling::orderBy('id','DESC')->paginate(10);
return view('backend.buy-sells.index',compact('data', 'topCategory'))
->with('i', ($request->input('page', 1) - 1) * 10);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Models\BuyingSelling $buyingSelling
* @return \Illuminate\Http\Response
*/
public function show( BuyingSelling $buyingSelling )
{
//dd( $buyingSelling->toArray() );
$getTopCategoryList = ProductCategory::getTopCategoryList();
return view('backend.buy-sells.show',compact( 'buyingSelling' , 'getTopCategoryList' ) );
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\BuyingSelling $buyingSelling
* @return \Illuminate\Http\Response
*/
public function edit(BuyingSelling $buyingSelling)
{
//dd($buyingSelling->id);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\BuyingSelling $buyingSelling
* @return \Illuminate\Http\Response
*/
public function update(Request $request, BuyingSelling $buyingSelling)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\BuyingSelling $buyingSelling
* @return \Illuminate\Http\Response
*/
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Country $buyingSelling
* @return \Illuminate\Http\Response
*/
public function destroy(BuyingSelling $buyingSelling)
{
$update['deleted_user_id'] = !empty(Auth::user()->id) ? Auth::user()->id : 0;
dd($buyingSelling->id);
$data = BuyingSelling::find($buyingSelling->id);
if( $data->delete() && $data->update([ 'deleted_user_id' => !empty(Auth::user()->id) ? Auth::user()->id : 0]) ) {
/*if( !empty($data->flag) ){
if( file_exists('public/storage/country/'.$data->flag) ){
unlink('public/storage/country/'.$data->flag);
}
}*/
$responseStatus = 'success';
$responseMessage = 'Buy & sell deleted successfully.';
}else{
$responseStatus = 'error';
$responseMessage = 'Something went wrong, please try again.';
}
//$add = CompanyBuyingSelling::create(['name' => $request->input('name')]);
return redirect()->route('buying-sellings.index')
->with($responseStatus, $responseMessage);
}
public function activeInactive($id)
{
$data = BuyingSelling::findOrFail($id);
//dd($data;die;
$responseMessage = '';
if($data->status == 0){
$input['status'] = 1;
$responseMessage = 'Buy & sell active successfully';
}else{
$input['status'] = 0;
$responseMessage = 'Buy & sell inactive successfully';
}
if( $data->update($input) ) {
$responseStatus = 'success';
}else{
$responseStatus = 'error';
$responseMessage = 'Something went wrong, please try again.';
}
//$add = BuyingSelling::create(['name' => $request->input('name')]);
return redirect()->route('buying-sellings.index')
->with($responseStatus, $responseMessage);
}
}