I am trying to pass 3 variables values inside an html link that uses route to access a named routed with this code:
{{$nomos->name}}
also the route function is
Route::get('gegonota/{gid?}/{cid?}/{nid?}', ['uses' => 'GegonosController#index', 'as' => 'gegonota']);
but it doesnt work right.
How can i do it.
thanks
you can try this.
{{$nomos->name}}
Just remove ? from your routes params so it will be :
Route::get('gegonota/{gid}/{cid}/{nid}', [
'uses' => 'GegonosController#index',
'as' => 'gegonota'
]);
if you want to use ? you need to provide a default value check the docs
and if you use Laravel v5.4 you need to change your route to :
Route::get('gegonota/{gid}/{cid}/{nid}', [
'uses' => 'GegonosController#index'
])->name('gegonota');
Related
I have laravel 5.5. Everything is working fine in it. I can access all routes.
But somehow I cannot access the route "/interest/{$id}".
This is my route.
<?php
Route::get('/interest/{$id}', [
'uses' => 'IdeaController#createInterest'
])->name('interest.create')->middleware('auth');
I Can access every route accept this one. I hope this helps.
Remove the dollar sign from your route parameter:
Route::get('/interest/{id}', [
'uses' => 'IdeaController#createInterest'
])->name('interest.create')->middleware('auth');
Route::get('/interest/{id}', [
'uses' => 'IdeaController#createInterest'
])->name('interest.create')->middleware('auth');
//in controller use method
public function createInterest($id){
}
I have a route like
http://localhost.fbleads.com/{dynamic-value}/auth/facebook-login
It give me error that route not found. Any solution for this
In your routes you could maybe have something like:
Route::get('{dynamic-value}/auth/facebook-login', [
'as' => 'auth.login',
'uses' => 'AuthController#login'
]);
the {dynamic_value} can be anything and be accessible as parameter in your controller method
I have the following route in my laravel route file:
Route::get('/{id}' , [
'uses' => 'PagesController#show',
'as' => 'getArticle'
]);
The problem with the above route is , its overriding the below route:
Route::resource('admin', 'adminController');
I want to keep my resource route, but how do i keep my resource ? is there a way around this ??
Modify your route file like this.
Route::resource('admin', 'adminController');
Route::get('/{id}' , [ 'uses' => 'PagesController#show', 'as' => 'getArticle' ]);
Route files executed in the order they are defined.
If you define Route::get('/{id}',.... in the beginning and set your url like http://your-site/admin, the admin section will be considers as the id for the Route::get('/{id}',.... route. So you need to keep it in your mind when you define your route.
just move this route in the end of the web.php file.
Route::get('/{id}' , [
'uses' => 'PagesController#show',
'as' => 'getArticle'
]);
There are two options:
move Route::get('/{id}', ...) after Route::resource(...)
or add a pattern to Route::get() if id is numeric Route::get('/{id}', ...)->where('id', '[0-9]+');
I have a Laravel 5.2 application where I want to display the same page on 2 different domains / routes. I have it working using the following route structure:
The routes to my primary domain:
Route::group(['domain' => 'www.primarydomain.com',
'prefix' => 'demo-page']), function(){
Route::get('/my-page', 'MyController#index');
Route::get('/my-second-page', 'MyController#getPageTwo');
}
The routes to my secundary domain (note: no prefix!):
Route::group(['domain' => 'www.secundarydomain.com',]), function(){
Route::get('/my-page', 'MyController#index');
Route::get('/my-second-page', 'MyController#getPageTwo');
}
The idea is that both routes will work, and they do. Both www.secundarydomain.com/my-page and www.primarydomain.com/demo-page/my-page work.
The issue is when I now want to generate a link to my second page. For building my URL's in my views, I'm using the following function to generate a link to my-second-page:
url('/my-page')
This function always generates a link to www.primarydomain.com/my-page, while I need a link to www.primarydomain.com/demo-page/my-page.
Is there any easy solution to resolve this? Can this be resolved using middleware, or will a custom URL function be needed?
Expected results:
url('my-page') on www.primarydomain.com should generate a link to www.primarydomain.com/demo-page/my-page
url('my-page') on www.secondarydomain.com should generate a link to www.secondarydomain.com/my-page
Easiest way to do that is to create your own helper, like custom_url() and use it instead of url().
You can look how original url() helper works and create similar one. Look here:
https://github.com/laravel/framework/blob/5.3/src/Illuminate/Foundation/helpers.php#L806
You can assign aliases to your routes.
Route::group(['domain' => 'www.primarydomain.com', 'prefix' => 'demo-page']), function(){
Route::get('/my-page', [
'as' => 'my_page_prefixed',
'uses' => 'MyController#index'
]);
Route::get('/my-second-page', [
'as' => 'my_second_page_prefixed'
'uses' => 'MyController#getPageTwo'
]);
}
And then you can call your aliased route on your blade templates by using {{ route('my_page_prefixed') }} or any other alias.
I have a route with parameter
Route::get('forum/{ques}', "ForumQuestionsController#show");
Now I want a route something like
Route::get('forum/add', ['middleware' => 'auth:student', 'uses' => "ForumQuestionsController#add"]);
well when I hit localhost:800/forum/add I get routed to ForumQuestionsController#show instead of ForumQuestionsController#add
Well I know I can handle this in show method of ForumQuestionsController and return a different view based on the paramter. But I want it in this way.
First give this one
Route::get('forum/add', ['middleware' => 'auth:student', 'uses' => "ForumQuestionsController#add"]);
Then the following
Route::get('forum/{ques}', "ForumQuestionsController#show");
Another Method (using Regular Expression Constraints)
Route::pattern('ques', '[0-9]+');
Route::get('forum/{ques}', "ForumQuestionsController#show");
If ques is a number it will automatically go to the show method, otherwise add method
You can adjust the order of routes to solve the problem.
Place add before show , and then laravel will use the first match as route .
Route::get('forum/add', ['middleware' => 'auth:student', 'uses' => "ForumQuestionsController#add"]);
Route::get('forum/{ques}', "ForumQuestionsController#show");
I think your {ques} parameter do not get properly. You can try this:
Route::get('forum/show/{ques}', "ForumQuestionsController#show");
Route::get('forum/add', ['middleware' => 'auth:student', 'uses' => "ForumQuestionsController#add"]);
If you use any parameters in show method add parameters:
public function show($ques){
}