mercredi 8 décembre 2021

Primary Key is different from the default id that laravel searches for

I have added a custom primary key within the table and now the Laravel is not even finding the result at all. giving error that the page could not be found.

NotFoundHttpException

No query results for model [App\usersinformation].

Controller --------------------

public function show(usersinformation $usersinformation)
{
    //
  //  $users =  $user = usersinformation::where('user-id','=',$usersinformation) -> first();
    
        return view('usersinformation.show');

}

Model -------------------

class usersinformation extends Model
{
    //

    public $table = "usersinformation";
    public $incrementing = false;
    
    protected $fillable = [

        'fname','lname', 'user-picture', 'phone-number', 'user-id', 'place-id'

    ];
    protected $primaryKey = 'user-info-id';

    public function users(){
        $this -> belongsTo('App\users');
    }

route ---- web.php

Route::post('/show','App\Http\Controllers\usersinformationController@show');

Still facing the same issue, if I comment the primary key, it will give error that the id field is not found within the table when I add the custom primary key in the model, it will give error page not found.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3duyEOI
via IFTTT

Aucun commentaire:

Enregistrer un commentaire