I am also having a hard time wrapping my head around this too. My goal of this exercise was to see if I could grab a page id from the pages table and it's description from the pageInfo table and have only that info displayed on the correct page based on the URL. So the URL: http://buddy/test_project/public/1 should only show the entry in the db that has an id of 1 and so on and so forth. Here's the code.
routes:
Route::get('/{id}', 'WelcomeController@Page');
Controller:
public function Page()
{
$p = Pages::leftJoin('pageInfo', function($join){
$join->on('pageInfo.id', '=', 'pages.id')
})
->where('pages.id', '=', \DB::raw('pageInfo.pages_id'))
->get();
dd($p);
}
Then of course the Pages model
class Pages extends Model {
protected $table = 'pages';
}
@JarekTkaczyk both solutions you listed worked, but listed all the rows in the db instead of only the row # from the URL.
The reason I started this exercise was because I needed to learn how to work with databases better and at the same time I needed to learn how to have the data in a database and grab that data according to which page the user is on, because these two tasks have been my biggest problem so far and I can't find any clear and concise explanation and examples anywhere.