PK

ADDRLIN : /home/questend/public_html/domains/evami.in/app/Http/Controllers/
FLL :
Current File : /home/questend/public_html/domains/evami.in/app/Http/Controllers/StoreController.php

<?php

namespace App\Http\Controllers;

use App\Store;
use Illuminate\Http\Request;
use Carbon\Carbon;
use Response;
use Redirect;
use Session;
use Auth;
use File;
use Illuminate\Support\Str;

class StoreController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth:admin');
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        if (view()->exists('backend.admin.stores.store'))
        {   
            $stores = Store::orderBy('store_sortby','desc')->paginate(5);
            $stores->withPath('store');
            return view('backend.admin.stores.store',compact('stores'));
        }
        return back()->with('message', 'Opps view not found');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        if (view()->exists('backend.admin.stores.storeCreate'))
        {   
            return view('backend.admin.stores.storeCreate');
        }
        return back()->with('message', 'Opps view not found');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        if ($request->_token != Session::token()) {
            return Redirect::back()->with('message', 'Invalid submission !');
        }
        $this->validate($request, [
            'store_name' => 'required',
            'store_image' => 'required',           
            'store_sortby' => 'required',
            'isactive' => 'required',
        ]);       
        $store = new Store();
        $store->store_name = Str::title($request->store_name); // Replaced title_case()
        $store->store_time = (!empty($request->store_time)) ? $request->store_time : 'N/A';
        $store->store_contactno = (!empty($request->store_contactno)) ? $request->store_contactno : 'N/A';
        $store->store_email = (!empty($request->store_email)) ? $request->store_email : 'N/A';
        $store->store_address = (!empty($request->store_address)) ? $request->store_address : 'N/A';
        $store->store_sortby = $request->store_sortby;        
        $store->isactive = $request->isactive;
        //$store->isdelete ='';
        $store->addedby = Auth::user()->id;
        $store->created_at = Carbon::now();
        $store->visitor = $request->ip();
        // Image Upload
            $destinationPath = 'images/store'; // Define destination path
            if ($request->hasfile('store_image')) {    
                $extension = $request->file('store_image')->getClientOriginalExtension(); // Get image extension
                $fileName = time().'.'.$extension; // Give name to image
                $img = $request->file('store_image')->move($destinationPath, $fileName); // Upload image to destination path
                $image_path = $destinationPath.'/'.$fileName; // Write image path in DB
                $store->store_image = $image_path;
                ##thumb destination path
                    //$thumimage_path = $destinationPath . '/thumb/' . $fileName; // thumb image path          
                    //resizeImage($image_path, $thumimage_path, $width=150, $height=150);     
            } else {
                $image_path = $destinationPath . '/' . time() . ($extension ?? ''); // Fixed undefined variable warning
                $store->store_image = $image_path;
            }
        if($store->save()){
            //return redirect()->route('admin.login');
            return redirect()->route('store.index')->with('success', 'New Store Added Successfully !');
            //return back()->with('success', 'New Category Added Successfully !');
        }
        return back()->with('error', 'Something went wrong please try again !');
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Store  $store
     * @return \Illuminate\Http\Response
     */
    public function show(Store $store)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Store  $store
     * @return \Illuminate\Http\Response
     */
    public function edit(Store $store)
    {
        if (view()->exists('backend.admin.stores.storeEdit'))
        { 
            return view('backend.admin.stores.storeEdit',compact('store'));
        }
        return back()->with('message', 'Opps view not found');
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Store  $store
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Store $store)
    {
        if ($request->_token != Session::token()) {
            return Redirect::back()->with('message', 'Invalid submission !');
        }
        $this->validate($request, [
            'store_name' => 'required',           
            'store_sortby' => 'required',
            'isactive' => 'required',
        ]);

        $store->store_name = Str::title($request->store_name); // Replaced title_case()
        $store->store_time = (!empty($request->store_time)) ? $request->store_time : 'N/A';
        $store->store_contactno = (!empty($request->store_contactno)) ? $request->store_contactno : 'N/A';
        $store->store_email = (!empty($request->store_email)) ? $request->store_email : 'N/A';
        $store->store_address = (!empty($request->store_address)) ? $request->store_address : 'N/A';
        $store->store_sortby = $request->store_sortby;
        $store->isactive = $request->isactive;
        $store->addedby = Auth::user()->id;
        $store->updated_at = Carbon::now();
        $store->visitor = $request->ip();
        // Image Upload
            $destinationPath = 'images/store'; // Define destination path
            if ($request->hasfile('store_image')) {    
                $oldFileName = $store->store_image;
                if ($oldFileName && File::exists(public_path($oldFileName))) {
                    File::delete(public_path($oldFileName)); // Fixed path concatenation
                }
                $extension = $request->file('store_image')->getClientOriginalExtension();
                $fileName = time().'.'.$extension;
                if($request->file('store_image')->move($destinationPath, $fileName)){
                    $store->store_image = $destinationPath . '/' . $fileName;
                } 
                ##thumb destination path
                    //$thumimage_path = $destinationPath . '/thumb/' . $fileName; // thumb image path          
                    //resizeImage($image_path, $thumimage_path, $width=150, $height=150);     
            }
        if($store->save()){
            //return redirect()->route('admin.login');
            //return redirect()->route('store.Edit')->with('success', 'New store Added Successfully !');
            return back()->with('success', 'Store Updated Successfully !');
        }
        return back()->with('error', 'Something went wrong please try again !');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Store  $store
     * @return \Illuminate\Http\Response
     */
    public function destroy(Store $store)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Store  $store
     * @return \Illuminate\Http\Response
     */
    public function delete(Request $request, $id)
    {
        if ($request->reqId > 0) {
            $id = (int)$request->reqId;
            //$store = Store::find($id);//FindOrFail($id);
            $store = Store::withTrashed()->findOrFail($id);
            $store->isdelete = 0;
            $store->addedby = Auth::user()->id;
            $store->deleted_at = Carbon::now();
            if ($store->save()) {
                $store = ['id' => $store->id, 'status' => true, 'msg' => 'Successfully deleted Store!']; // Fixed message
                return response()->json($store);
            }
            $store = array_merge($store ?? [], ['status' => false, 'msg' => 'failed to delete Store!']); // Fixed array_merge() and message
            return response()->json($store);            
        }             
    }

    public function restore($id = 0) 
    {
        if($id > 0) {
            $store = Store::withTrashed()->find($id)->restore();
            $store = Store::find($id);
            $store->isdelete = 1;
            $store->save();
            return back()->with('info', 'Restore store successfully !'); // Fixed message
        } else {
            $store = Store::onlyTrashed()->restore();//->get();
            $store = Store::where('isdelete', 0)->update(['isdelete' => 1, 'addedby' => Auth::user()->id]);         
            return back()->with('info', 'Restore store successfully !'); // Fixed message
        }        
        return self::index();
    }
}


PK 99
E-SHOP || DASHBOARD
404

Page Not Found

It looks like you found a glitch in the matrix...

← Back to Home