laravel prefix not working in route - laravel

Route::group(array('prefix'=>'admin','middleware' => 'auth_admin_check'), function() {
Route::any("dashboard",["as"=>"admin_login_post1","uses"=>"admin\DashboardController#index"]);
});
after login i am redirecting to the page: dashboard but my prefix : 'admin' was not added.

I think you're redirecting to a url? Do you redirect to '/dashboard'? This will not prefix it.
What you should use is
redirect(route('admin_login_post1'))
This will retrieve the url by the route's name. Laravel will find the route in a group with a prefix, so Laravel will prefix the URL.
The route() function is very usefull. When you change a url, you don't have to change it troughout your whole application. This is because the function retrieves the url from the routes file. So if you change it in the routes file, you change all the links in your application.

if your prefix "admin" is not loading in the URL, then may be there is another route declared for /dashboard. check for that
and for redirection, use
redirect()->route('admin_login_post1');

Related

Laravel subdomain route problame

I am working on a subdomain system on laravel.
suppose my main domain name is: test.test
and my subdomain name is: subdomain.test.test
Now, the problem is, when I use the main domain route in sub-domain blade file like:
Profile
then, it should generate links like test.test/profile
but, it's generating links with subdomain like: subdomain.test.test/profile
Now, How can I solve this problame?
An alternative would be to use relative path instead of absolute using route() helper third parameter.
Profile
I recommend you to use Spatie Multitenancy, when i do route('home'), he return back the url with the actual domain.

vue-router url can't find when its revisite/reload in laravel project

When i re hit the vue-router url its return 404 page not found.
I running it on laravel 5.8. in web.php file
I tried some of these but they don't work
Route::get('/{capture_all?}', 'HomeController#index')->where('capture_all', '[\/\w\.-]');
Route::get('/{vue_capture?}', 'HomeController#index')->where('vue_capture', '[\/\w\.-]');
Route::get('/{any}', 'HomeController#index')->where('any', '[\/\w\.-]');
the page will refreshed
Consider a fallback route:
Route::fallback('HomeController#index');
Any unknown route will be passed to this fallback route. Any known routes (like to your APIs) will remain untouched.

Building on Laravel API backend and Vuejs frontend

I would require a little help here if this method will work out well.
Firstly, I have a backend API server created using Laravel and Laravel Passport. Secondly, I have also created the frontend with Vuejs within the same project. As such, I will be required to use both the api.php and web.php routes. I am also redirecting these routes using vue-router.
Backend
Inside the web.php routes, I have used two different routes because I want to display generic contents on my landing site and the other as an authentication required dashboard.
Example:
web.php
As above, this is to capture the routes which are 404 Not Found that are directly manipulated in the address bar to redirect correctly to their respective pages. I also ended up having two different blade templates named as dashboard.blade.php and home.blade.php respectively. Is this an okay practice for a Laravel-Vuejs project? Or are there ways that you would like to recommend?
dashboard.blade.php
home.blade.php
Login related problem with login page using the layout of the landing page into another layout of the dashboard page
The problem that I am faced with when doing an API login with the password grant is that the login page does not redirect to the dashboard page properly. The URL route does change but the page is rendered as blank.
The login using axios here:
I have managed to fix the problem.
In web.php, since we have
Route::get('/dashboard/{any?}', function () {
return view('dashboard');
})->where('any', '^(?!.*api).*$[\/\w\.-]*');
Inside of my Login.vue redirect handler, I use location.href = '/dashboard' instead of this.$router.push('dashboard').

Laravel - can we create a master route that redirects every link to the profile page if the same has not been filled in as yet

In laravel, I want the users to create their profile before they can access any other link of the application. Can we create a master route that redirects every link to the profile page if the same has not been filled in as yet.
You would have to wrap all your routes in a middleware that checks if their profile has been filled, if this fails then redirect them to the profile page.
one Possible solution would be this :
Create a variable for each user to say true if his profile is filled or false if not.
then create a middleware to check that variable. if its false to redirect to profile page... your logic. read here for middleware https://laravel.com/docs/5.4/middleware
wrap all your routes with that middleware
in your route file
Route::group(['middleware' => 'yourmiddlewarename'], function() {
//all routes
});

codeigniter routes

How to redirect controllers if they not match pattern.
For example I have follow controllers about_us, contacts, find_us. How to do so If the request method is not in that selection to be redirected to other controller ?
For some reason it's not in the documentation for URI Routing in the User Guide. If you are using CI2, inside of your routes.php file you can use "404_override". It is one of the reserved routes.
$route['404_override'] = "error";
So when a user comes to a controller that is not one you have created or not something inside your routes.php file, it throws them into the "error" controller. Obviously you would have to make a controller called "error"
Read about routing.

Resources