Chris Sevilleja
Making scotch.io. Google Dev Expert. Champion pizza maker.
The foundation of every application.
app/Http/routes.php
Route::get('about', function() {
return view('about');
});app/Http/routes.php
Route::get('@{username}', function($username) {
return "The user is {$username}.";
});http://example.com/@chris
outputs
The user is chris.
app/Http/routes.php
Route::get('users/{type?}', function($type = null) {
if (is_null($type)) {
// get all users
} else {
// if type exists, get that type
}
});app/Http/routes.php
Route::get('@{username}', ['as' => 'profile', function($username) {
return view('profile');
}]);Create a URL
$url = route('profile', ['username' => $username]);<a href="{{ route('profile', ['username', $username]) }}">
{{ $username }}
</a>What if we switch from @{username} to just {username}?
No code changes required.
app/Http/routes.php
Route::group([
'prefix' => 'dashboard'
], function() {
// dashboard routes go here
});app/Http/routes.php
Route::group([
'domain' => '{username}.mysite.com'
], function() {
// user site specific routes go here
});app/Http/routes.php
Route::group([
'namespace' => 'Dashboard',
'prefix' => 'dashboard'
], function() {
// this route is myapp.com/dashboard
// this will use app/Http/Controllers/Dashboard/DashboardController.php
Route::get('/', 'DashboardController@getHome');
});app/Http/routes.php
Route::get('dashboard', 'Dashboard\DashboardController@getHome');// app/Http/routes.php
Route::get('@{user}', 'SiteController@getProfile');
// app/Http/Controllers/SiteController.php
public function getProfile(User $user) {
// entire user object
dd($user);
}// get the full url
Request::current();// get a section of the url
Request::segment(1);By Chris Sevilleja