11/1/19

Views in Laravel - Part - 6




Views (Resouses-> views)
---------------------------------------------

resourses -> view -> welcome.blade.php (default file) is default 'Laravel' home page such as cms.test which means http://localhost/cms/public (laravel 5 welcome page)

The reason why we use these '.blade' because PHP uses a templating engine a features special programming, laravel uses that to do things easier with PHP.

if you want any page, you may create that place.

Let's use sources we gotta here.it's controller post controller to displacement view. (HTTP->Controller->PostsControllers.php)

search fast files in PHP storm ide (press twice shift key)

--------------------------------------------

how to create a route to the PHP file:

1. go to the resources -> view and create a new directory such as pages
2. go to the pages and create the PHP file
3. go to the PostsControllers and create a custom control.

custom control:
public function contact(){
  return view('pages/contact');
}

or

public function contact(){
  return view('pages.contact');
}

4. finally call the controller in route.php

Route::get('/contact',PostsController@contact');



------------------------------------------
how to pass data into view:

It's time for us to learn how to pass data into view.

1. create a custom method in routes.php

Route::get('post/{id}','PostsController@show_post');

2. Go to the PostsController

public function show_post($id){
        return view('post');
}

3. go to the resources -> view and create a new PHP file that name was 'post.blade.php'


-------------------------------------------------

.blade:
php uses a templating engines a featire a special programming laravel uses that too.

No comments:

Post a Comment

About

Hi, I'm Najathi.
I've started entrepreneurial company, Twin Brothers.Inc.
One is self-funded & the other is venture backed. I also send a weekly. where I share relevent, curated links.

Every Week I Publish a short post on writing, publishing, or content of IT Related

Contact Form

Name

Email *

Message *