[Vuejs]-Unable to insert data in the database in laravel projet with vuejs and vuetify

0👍

yeah, the issue in your LocationController.php file, you missed commas in Location::create . Also, show function has a problem. notice carefully.

<?php
namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Location;

class LocationController extends Controller
{

    public function index(Request $request)
    {  
        $per_page = $request->per_page ? $request->per_page : 5;
        $sort_by = $request->sort_by;
        $order_by = $request->order_by;
        return response()->json(['locations' => Location::orderBy($sort_by, $order_by)->paginate($per_page)],200);
    }

    public function store(Request $request)
    {
        $location= Location::create([
            'code' =>$request->code,
            'name' =>$request->name,
            'description' =>$request->description
        ]);
        return response()->json(['location'=>$location],200);
    }


    public function show($id)                                                                                                                                                           
    {
        $locations = Location::where('code','LIKE', "%$id%")->orWhere('name','LIKE', "%$id%")->orWhere('description', 'LIKE', "%$id%")->paginate();
        return response()->json(['locations' => $locations],200);
    }



    public function update(Request $request, $id)
    {
       $location = Location::find($id);
       $location->code  = $request->code;
       $location->name  = $request->name;
       $location->description  = $request->description;
       $location->save(); 
       return response()->json(['location'=>$location], 200);
    }

    public function destroy($id)
    {
        $location = Location::where('id', $id)->delete();
        return  response()->json(['location'=>$location],200);
    }

    public function deleteAll(Request $request){
        Location::whereIn('id', $request->locations)->delete();
        return response()->json(['message', 'Records Deleted Successfully'], 200);
    }
}

Leave a comment