vendredi 29 juillet 2016

Laravel join inside controller

I'm trying to print out from array into view but it always says ('Illuminate\Database\QueryException with message 'SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'stations' (SQL: select * from stations inner join stations on stations.id = users.station)'

This is function inside controller

public function show()
    {
$users = App\Classes::join('stations','stations.id','=', 'users.station');
return view('configuration.configuration', compact($users));
}

This is model Stations and model users

public function user()
{
    return $this->hasMany('App\User');
}

public function razred()
{
    return $this->belongsTo('App\Classes');
}

and the foreign key is in table users

$table->integer('station')->nullable()->unsigned()->default(null);
$table->foreign('station')->references('id')->on('stations')->onDelete('cascade');



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2aDYmzJ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire