In What Way Can I Combine Laravel and Angular to Vender Views
I am building an app which is not a Single Page Application. I want to use both laravel and angular js. but i dont want a situation where by Angular becomes responsible of rendering all the pages alone but in some cases, laravel will also render some pages when a user clicks on a link. Just like Gitbuh.com when you click on commits.
My question is how do i combine the two and how do i structure my route?
My question is how do i combine the two and how do i structure my route?
You don't require separate routes for this. In the action for the routes which will respond to both types of queries, just check if its an ajax request or json is asked for then return json else return view.
Even you can place this as view. No need to use file facade
Route::any('/', function () {
return view('templates.welcome'); //return File::get(public_path().'/advert-templates/welcome.html');
})->where('angular', '.*');
public function getAdvertView(Request $request) {
$data = $whatever; // whatever data you are collecting for the view
if($request->ajax() || $request->wantsJson()) {
return $data;
}
return view('view-name',compact('data'));
}
I seriously don't get it. First try working with angular as such without laravel, make your self comfortable with router, templates etc, and then we shall tackle the laravel specific implementation