samedi 20 mars 2021

Error Message: "The GET method is not supported for this route. Supported methods: POST"

when i access to endpoint this http://localhost/newsapp_api/public/api/register,this message is showed "The GET method is not supported for this route. Supported methods: POST". look to the link below

but when i tried register new user and entered data(name,email,password) for user by postman program this message is showed "message": "Undefined property: Illuminate\Database\Query\Builder::$map". and it doesn't give json data. look to the link below

api.php

Route::POST('register', 'App\Http\Controllers\Api\UserController@store');

UserController.php

public function store(Request $request)
    {
        $request->validate([
            'name'  => 'required',
            'email' => 'required',
            'password'  => 'required'
        ]);
        $user = new User();
        // $user->name = $request->get( 'name' );
        // $user->email = $request->get( 'email' );
        // $user->password = Hash::make( $request->get( 'password' ) );
        $user->name = $request->name;
        $user->email = $request->email;
        $user->password = Hash::make( $request->password );
        $user->save();
        return new UserResource( $user );
    }

UserResource.php

<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Http\Resources\Json\Resource;

class UserResource extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return parent::toArray($request);
    }
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire