I have an app built with Laravel 5.1. I'm using Form::open using a route_name to generate the url to post the form to as well as creating links by defining route and using the UrlGenerator. The issue is that I have some buttons/links created for display purposes and do not have pages created yet.
I get a route not defined error with stack trace going back to UrlGenerator line 296. I'm wanting to set up something so that the error does not display. Instead, I would like a link to be generated to the pre-defined page that I have created saying that the feature the user clicked on is not yet developed.
I thought about doing something similar to a 404 error, but the issue is that the existing page (the page the link or button lives on) is not being displayed, not just that route is missing.
For example, below, I create a link to the route "broker_contact_create" Since this route does not exist, the page displaying the link will not load. Instead, I get the error saying:
ErrorException in UrlGenerator.php line 296: Route
[broker_contacts_create] not defined. (View:
index.blade.php)
<div class="col-md-6 col-lg-7 margin-bottom-15">
+ Add Contact
</div>
Instead, I want the page to be displayed. When the user clicks on the link to a missing route, to have them routed to a page that tells the user they clicked on a link to a feature that has not been enabled yet.
So basically I just want it to do: if route not found then provide $url.
If you follow the stack trace, you'll see that the route function basically invokes UrlGenerator->route
https://github.com/laravel/framework/blob/5.1/src/Illuminate/Routing/UrlGenerator.php#L300
Which checks if the route with that name exists, and if not, throws an InvalidArgumentException.
Basically, what you're trying to do is not possible. You must define that route if you want to use the route function.
I think your best option is to set up a "feature not developed" view, and point all of these pending routes to that view. That way you can use the route function. Your link/button will be generated, but will take them to a "not yet developed" page. Another benefit to this is that all of your routes are laid out and you can easily see which ones need to be developed.
Route::get('/brokers/contacts/create', ['uses' => 'HomeController#notDeveloped', 'as' => 'broker_contact_create']);
And inside your HomeController:
public function notDeveloped() {
return view('pages.not_developed');
}
Related
I am new to CodeIgniter 4.
I have one controller named Pages and helps to display website pages normally. Then I have another controller named Admin which is suppose to load the admin view with its own header and footer files.
While Pages controller works fine, the Admin controller keeps saying 404-file not found admin.
I think I have a problem with my current Route settings below. Please help.
$routes->setDefaultController('Pages');
$routes->setDefaultMethod('default');
// Route Definitions
$routes->get('/', 'Pages::index');
$routes->get('(:any)', 'Pages::default/$1');
try ajusting your code like this.
$routes->setDefaultController('Pages');
$routes->setDefaultMethod('default');
// Route Definitions
$routes->resource('pages');
$routes->get('/', 'Pages::index');
$routes->get('(:any)', 'Pages::default/$1');
Sorry for asking this question. I'm new to laravel and I'm trying to find out the location of the responsible script of sending the notification on submite button event.
When I go to
http://127.0.0.1:8000/push-notificaiton
You know there you fill the title and message then you submit it to a script or code where you find the targeted auth username.
I want to know the location of that code to edit it in order to do one more things such as inserting title and message in database after sending the push notification to use.
For laravel 4.2
Go to app/routes.php. Search for 'push-notificaiton'. You will find a controller and function next to the url. Go to the controller and find the function
For laravel 5 - 5.2
app/Http/routes.php
From version 5.3 - 8
routes/web.php
In your routes/web.php file, you should find a route for that URL. You'll also find the name of a controller next to it. Open up that controller and you'll see the code for the route.
Sorry in advance, I know it has been asked before but I did not figure out the solution.
I am new to Laravel, still learning and stuck with this issue:
My objective is to add pages in admin and show these pages in frontend.
For the Front part of the website I have this route:
Route::get('/{page}', 'PagesController#show');
so the when you access /about, /contact, /another-page I use the same view
For the Admin part of the website I have this route:
Route::get('/admin', 'AdminController#show');
My problem is that the first route overwrites the second route and I don't know how to avoid this.
I have tried with namespaces and grouping routes, but I get the same outcome.
Thank you
To make it simple this is happening because you have the route with the parameter before the admin route so is going to send the "admin as a parameter of page"
The Simple fix is just put admin route before your "/{page} so it will find admin route first,Something Like this:
Route::get('/admin', 'AdminController#show');
Route::get('/{page}', 'PagesController#show');
But I do not recommend building your routes this way and have specifics pages setup if possible, This way of building routes will mess around with the 404 route not found aswell.
I would like to have different login view for different subdomain.
My system has 2 modules for login.
-Member: www.example.com
-Agent: agent.example.com
I would like to implement 2 different login layout also different flow but using same users table.
-Member: www.example.com/login
-Agent: agent.example.com/login
inside my routes/web.php
Route::domain('agent.example.com')->group(function () {
Route::get('/login', 'AgentController#showLoginForm')->name('agent.login');
});
However, it still show my member login screen.
But if I changed to
Route::domain('agent.example.com')->group(function () {
Route::get('/agent-login', 'AgentController#showLoginForm')->name('agent.login');
});
It display the correct controller and view.
I already added the Route::domain to filter up. But how come Laravel still pick up the original login route?
How do I separated it? I prefer to have agent.example.com/login instead of agent.example.com/agent-login
It is because I am using acacha/adminlte-laravel packages. It has the login route included in the package.
Laravel route is organized based on priority of matching. So you want your route match first, you have to put in on the top.
And due to acacha/adminlte-laravelset the Auth::route inside the package. So I can't manually set the route priority in web.php.
What you have to do is remove the Auth::route in vendor. Fork your own repo. and do the customization.
This might be a very silly question because I'm new to PHP frameworks. But I have got the concept of MVC framework. But this routing thing is very confusing me.
I created a controller and view for dashboard and set it as default. Then I wanted to check if the user is logged in then send him to the login page if it's not.
So, what I did in the routes is this:
$route['default_controller'] = 'dashboard/index';
$route['login'] = 'login';
But even if I add a thousand more controllers and routes, it still goes to the default i.e the dashboard. This was supposed to work http://localhost/codeigniter/login. I'm very sure I haven't put a redirect-to-dashboard code in the login page.
at first it's important to understand to routing in codeigniter.
The key for understanding is $route['url/path'] = controller/method (or "public function")
So. In your case, you routing to Login controller and index method (or index function...this it interpretation of codeigniter )
If you want to check if is user logged or not, you may try to check for examle session variable inside of called functon. But it depends on your application. But I think that is not good idea to check it in routes.php
Hope it helps you.
The default controller in routes, will be the controller that opens your index or first page.
If your first page is in controller "pages", then that is your default controller. Do not use it for your secure dashboard pages
Your first page should be the index method in the controller. It should look like this
$route['default_controller'] = "pages";
Where pages is your first page controller