mercredi 19 mai 2021

I can't work out why this Laravel API keeps returning a 404

I have this controller:

    <?php

namespace App\Http\Controllers\API;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Assetgroup;
use App\Models\Asset;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;


class AssetgroupController extends Controller
{
    
    
    public function __construct()
    {
        $this->middleware(['jsonvalidation:CreateAssetGroupResource'])->only('store');
        $this->middleware(['jsonvalidation:CreateAssetGroupResource'])->only('update');
    }
   
    public function update(Request $request, Assetgroup $assetgroup, Asset $asset = null)
    {
        **********


    }

This route in api.php

Route::apiResource('/assetgroups', 'API\AssetgroupController');

And it's being called fromt his axios request

Axios.put(`${API_URL}assetgroups/${division.id}`, {
            added
        }).then(r => {
            // DETECT ERROR

            toast('Users assigned!', {
                type: toast.TYPE.SUCCESS,
                autoClose: 2500
            });

            this.setState({
                added: [],
                selectedUsers: r.data.selected_users,
                saving: false,
                users: r.data.users
            });
        });

I am new to laravel, and I cannot work out why this isn't working. The browser returns a

Request URL: http://127.0.0.1:8000/api/assetgroups/22
Request Method: PUT
Status Code: 400 Bad Request
Remote Address: 127.0.0.1:8000
Referrer Policy: strict-origin-when-cross-origin

Any help would be appreciated. Thankyou.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire