So in the laravel documentation in laravel 5.2 it stated that this is how facade is implemented in laravel.
<?php
namespace App\Http\Controllers;
use Cache;
use App\Http\Controllers\Controller;
class UserController extends Controller
{
/**
* Show the profile for the given user.
*
* @param int $id
* @return Response
*/
public function showProfile($id)
{
$user = Cache::get('user:'.$id);
return view('profile', ['user' => $user]);
}
}
Could we do this instead?
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Cache;
use App\Http\Controllers\Controller;
class UserController extends Controller
{
/**
* Show the profile for the given user.
*
* @param int $id
* @return Response
*/
public function showProfile(Cache $cache, $id)
{
$user = $cache->get('user:'.$id);
return view('profile', ['user' => $user]);
}
}
From what I can see I think that
use Cache;
is just encapsulating the call to
Illuminate\Support\Facades\Cache
am I correct? The application bootstrap that namespace into that alias I believe?
More clarification would definitely help. I'm new to laravel.Anything that I explained or described wrong please correct me thanks.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1OeNpzM
via IFTTT
Aucun commentaire:
Enregistrer un commentaire