Laravel Framework

Setting up first route,view,controller and sending data to view laravel 5

Example Route

Route::get('home','HomeController@index');  // you tell if url has /home then home controller index function handles that

Then Controller will be

namespace App\Http\Controllers;
class HomeController extends Controller
	//this is the funtion handling the /home
	public function index(){
		$data = "abc"; // here is sample data
	    return View::make('home/myhome', array('data' => $data));  // this is html file will be saved in views/home/myhome.blade.php



{{ $data }} 

Model relations and Querying Laravel

Posts model may look like below

    public function tags(){
        return $this->hasMany('App\Models\Posttag','post_id','post_id');
    public function user(){
        return $this->belongsTo('App\Models\User','user_id');
    public function comments(){
        return $this->hasMany('App\Models\Comment','post_id','post_id');
    public function comments_count(){
        return $this->hasOne('App\Models\Comment','post_id','post_id')->selectRaw('post_id, count(*) as aggregate')->groupBy('post_id');

Then we can query data like so

	   $data = Post::with(['tags','comments' => function($query){
			},'user' => function($query){