model view controller - Is it a good practice to use require_once in the .blade.php template? -
normally we'll use like
<?php require_once 'init.php'; //file start session, connect database etc. ?> <!-- html content here--> head body etc. <!---------------------->
but when you're building .blade.php template. thing work way? mean template like
<?php require_once 'init.php'; ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>@yield('title')</title> <link rel="stylesheet" href="../public/css/bootstrap.min.css" media="screen"> <link rel="stylesheet" href="../public/css/tpl.css"> <link rel="stylesheet" href="../public/fonts/font.css"> </head> <body> @yield('header') @yield('content') @yield('footer') </body> </html>
is best practice or there better way this?
i recommend study laravel authentication doesn't require such steps.
laravel handles such works you.
here laravel authentication document
if using laravel 4.2, then
in routes, should add
route::group(array('before' => 'auth'), function(){ #your request here});
here sample route your
route::get('home', 'yourcontrollerr@yourgeneralfunction'); route::group(array('before' => 'auth'), function() { route::get('dashboard', 'yourcontrollerr@yoursecurefunction'); });
in above routes url home
can accessed (public). url dashboard
can accessed logged in user.
if using laravel 5 or above, simple
you can check user by
if user guest then
@if(auth::guest())
or if user authenticated then
if (auth::check()) { // user logged in... }
or
@if( auth::check() ) current user: {{ auth::user()->name }} @endif
Comments
Post a Comment