I am building a login page for the user in which one can sign up by filling the sign up form or can login with facebook.
Login with facebook is working fine and is routing to the user's profile page whereas when one logins after registering on the site ,error occurs stating that "route[myplace] not defined which is working in case of login with facebook.
My routes.php file:
Route::get('/', function () {
return view('welcome');
})->name('home');
Route::post('/signup' , [
'uses' => 'UserController#postSignUp' ,
'as' => 'signup'
]);
Route::post('/signin' , [
'uses' => 'UserController#postSignIn' ,
'as' => 'signin'
]);
Route::get('/myplace' , [
'uses' => 'UserController#getmyplace' ,
'as' => 'myplace' ,
'middleware' => 'auth:web'
])->name('myplace');
Route::get('/verify' , [
'uses' => 'UserController#getverify' ,
'as' => 'verify'
]);
Route::get('login', 'Auth\AuthController#redirectToFacebook');
Route::get('login/callback', 'Auth\AuthController#getFacebookCallback');
my postSignIn function in UserController.php:
public function postSignIn(Request $request)
{
$this->validate($request,[
'email'=> 'required' ,
'password' => 'required'
]);
if(Auth::attempt(['email'=>$request['email'], 'password' => $request['password']]))
{
return redirect()->route('myplace');
}
return redirect()->back();
}
Actually,I was using same route for different controllers.So ,i just copied my myplace function from UserController.php to AuthController.php and it worked.
Related
I've got 2 sections to my site, the admin side and the public side. The issue I'm having is that if I go to for example admin/menus then I go to my public side instead of going to the menus page.
I'm not sure why this is happening. I've tried to re-arrange the order of the routes in my public side but that didn't work and I've drawn a blank as to what I've done wrong.
My public routes
<?php
Route::get('/', [
'uses' => 'OpenController#index',
'as' => 'index',
]);
Route::get('/{id}', 'OpenController#content');
Route::post('/contact', [
'uses' => 'OpenController#contact',
'as' => 'contact',
]);
Route::get('/{category}/{slug}', [
'uses' => 'OpenController#productItem',
'as' => 'product.item',
]);
Route::any('/search', [
'uses' => 'OpenController#search',
'as' => 'search'
]);
my admin menus route
Route::resource('admin/menus', 'MenusController');
My productItem function
public function productItem($category, $slug)
{
$menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
$contact = Contact::all();
$single_product = Product::where('slug', $slug)->get();
return view('open::public.single_item', compact('menus_child', 'contact', 'single_product'));
}
The error come in with this route
Route::get('/{category}/{slug}', [
'uses' => 'OpenController#productItem',
'as' => 'product.item',
]);
If I remove this route then it works, but I need this route so I can't remove it.
If I'm missing something else that I need to give please let me know.
This will work if u put it at the top, but it may clash with other routes i think.
Route::get('/{category}/{slug}', [
'uses' => 'OpenController#productItem',
'as' => 'product.item',
]);
you can try like this if u want
Route::get('/category/{category}/{slug}', function (\Illuminate\Http\Request $request) {
echo "ok";
});
You should prefix the route /{category}/{slug} to avoid conflicts. So replace:
Route::get('/{category}/{slug}', [
'uses' => 'OpenController#productItem',
'as' => 'product.item',
]);
By:
Route::get('/open/{category}/{slug}', [
'uses' => 'OpenController#productItem',
'as' => 'product.item',
]);
And update your links to that route in your views.
Route::get('/{category}/{slug}', [
'uses' => 'OpenController#productItem',
'as' => 'product.item',
]);
Will catch every combination of path that have two items /admin/menus, /admin/anything or /foo/bar. You are probably going to run into the same problem with
Route::get('/{id}', 'OpenController#content');
If you can not rename your routes, you need to put all the more restrictive routes on top and your less restrictive routes on the bottom.
Route::resource('admin/menus', 'MenusController');
Route::get('/', [
'uses' => 'OpenController#index',
'as' => 'index',
]);
Route::post('/contact', [
'uses' => 'OpenController#contact',
'as' => 'contact',
]);
Route::any('/search', [
'uses' => 'OpenController#search',
'as' => 'search'
]);
Route::get('/{category}/{slug}', [
'uses' => 'OpenController#productItem',
'as' => 'product.item',
]);
Route::get('/{id}', 'OpenController#content');
UPDATE
You have a few options.
Here are two of them.
You can limit what the route will accept with RegEx.
See Route Parameters > Regular Expression Constraints
Route::get('/{category}/{slug}', function () {
return 'hello';
})->where('category', '[one]*[two]*[three]*[four]*[five]*');
Or you can change the caffeine route through its config.
php artisan vendor:publish --tag=genealabs-laravel-caffeine
Then change the route in /app/config/genealabs-laravel-caffeine.php
There are some other ways as well. I'd just up a quick test site and start messing with routes to see what works the best for your needs.
I am somewhat new to Laravel.
I have created a form, submitted it for authorisation but then I am told (by Firefox) the routing will never complete. I know the login has worked as I intercepted it.
Here is my routes.php:
Route::get('/',function()
{
return view('welcome');
})->name('home');
Route::get('/welcome', function () {
return view('welcome');
});
Route::post('/signin',
[
'uses' =>'UserController#postSignIn',
'as' => 'SignIn'
]);
Route::get('/dashboard',
[
'uses' => 'UserController#getDashboard',
'as' => 'DashBoard',
'middleware' => 'auth'
]);
Route::get('/logout',
[
'uses' => 'UserController#getLogout',
'as' => 'Logout'
]);
and here is the UserController:
class UserController extends Controller
{
public function postSignIn(Request $request)
{
$this->validate($request,
[
'email' => 'required | email',
'password' => 'required'
]);
if (Auth::attempt([ 'email' => $request['email'], 'password' =>$request['password'] ]) )
{
//exit("authorised");
$message = "you are now logged in";
return redirect()->route('DashBoard')->with(['successmessage' =>$message]);
}
else
{
$message = "username\password combination not correct";
//exit('not - email = '.$request['email'].' password = '. $request['password']);
return redirect()->back()->with(['errormessage' => $message] );
}
}
public function getLogout()
{
Auth::logout();
return redirect()->route('home');
}
public function getDashboard()
{
return redirect()->route('DashBoard');
}
}
As can be seen by what is commented out the authorisation is OK
But I get this from Firefox
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
Just use to() in your return as
return redirect()->to('DashBoard')->with(['successmessage' =>$message]);
add this to your route
Route::get('/signin',
[
'uses' =>'UserController#postSignIn',
'as' => 'SignIn'
]);
After completing my project in localhost, I had upload my project to the server suppose the url is www.example.com. I upload the entire project to the public_html and movie all the file from public to the root i.e public_html and edit index.php to point to the bootstrap autoload.php and app.php . But when I try to access the url like www.example.com, I get error like
This webpage has a redirect loop
ERR_TOO_MANY_REDIRECTS
My routes.php is
<?php
Route::get('/dashboard',array(
'as' => 'dashboard',
'uses' => 'UserController#index'
));
Route::get('/dashboard/activate_user', array(
'as' => 'active-user',
'uses' => 'UserController#activate_user'
));
Route::post('/dashboard/activate_user',array(
'as' => 'active-user',
'uses' => 'UserController#activate_user_post'
));
/**
* User routes
*/
//display the form to add user
Route::get('/dashboard/create_user',array(
'as' => 'create-user',
'uses' => 'UserController#create_user'
));
//insert data into db
Route::post('/dashboard/create_user', array(
'as' => 'create-user-post',
'uses' => 'UserController#create_user_post'
));
//list user
Route::get('/dashboard/list_users',array(
'as' => 'list-user',
'uses' =>'UserController#list_users'
));
//view user
Route::get('dashboard/view_users/{id}',array(
'as' => 'view-user',
'uses' =>'UserController#view_users'
));
//delete user
Route::get('dashboard/delete_user/{id}',array(
'as' => 'delete-user',
'uses' => 'UserController#delete_user'
));
//edit user
Route::get('dashboard/edit_user/{id}', array(
'as' => 'edit-user',
'uses' => 'UserController#edit_user'
));
Route::post('dashboard/edit_user/{id}',array(
'as' => 'edit-user',
'uses' => 'UserController#edit_user_post'
));
/* (Painfully) Using laravel magic */
// Authentication routes...
Route::get('auth/login', 'Auth\AuthController#getLogin');
Route::post('auth/login', 'Auth\AuthController#postLogin');
Route::get('dashboard/logout', 'Auth\AuthController#getLogout');
// Registration routes...
Route::get('auth/register', 'Auth\AuthController#getRegister');
Route::post('auth/register', 'Auth\AuthController#postRegister');
//service controller
Route::get('dashboard/add_service','ServiceController#create');
Route::post('dashboard/add_service','ServiceController#store');
Route::get('dashboard/list_service','ServiceController#index');
Route::get('dashboard/edit_service/{id}','ServiceController#edit');
Route::post('dashboard/edit_service/{id}','ServiceController#update');
Route::get('dashboard/delete_service/{id}','ServiceController#destroy');
//profile controller
Route::get('/dashboard/profile/edit/org/{id}',array(
'as'=> 'edit-org',
'uses'=>'ProfileController#editOrg'
));
Route::post('/dashboard/profile/edit/org/{id}',array(
'as'=> 'edit-org-post',
'uses'=>'ProfileController#updateOrg'
));
Route::get('/dashboard/profile/edit/person/{id}',array(
'as'=> 'edit-person',
'uses'=>'ProfileController#editPerson'
));
Route::post('/dashboard/profile/edit/person/{id}',array(
'as'=> 'edit-person-post',
'uses'=>'ProfileController#updatePerson'
));
Route::get('/dashboard/profile/edit/logo/{id}',array(
'as' => 'edit-logo',
'uses' => 'ProfileController#deleteImage'
));
Route::get('/search',array(
'as' => 'search-result',
'uses' => 'SearchLogController#index'
));
Route::post('/agent-search-log',array(
'as' => 'agent-search-log',
'uses' => 'SearchLogController#agentSearchLog'
));
/* route to display the search log graph **/
Route::get('/search/graph',array(
'as' => 'search-result-graph',
'uses' => 'SearchLogController#searchFlightGraph'
));
Route::post('/search/graph/agent',array(
'as' => 'search-result-agent-graph',
'uses' => 'SearchLogController#searchAgentFlightGraph'
));
Route::post('/search-from-to',array(
'as'=> 'download-search-log',
'uses'=> 'SearchLogController#downloadFromTo'
));
/* excel route */
Route::get('/search/download',array(
'as' => 'search-download-excel',
'uses' => 'SearchLogController#downloadExcel'
));
In my application, I have the concept of events. Each event can be booked by a user, and also unbooked if that user needs to cancel.
My event routes look like this:
Route::get('events/search', 'EventsController#search');
Route::get('events/past', 'EventsController#past');
Route::get('events/{id}/invite', [
'as' => 'invite', 'uses' => 'EventsController#invite'
]);
Route::get('events/{id}/invite/groups', [
'as' => 'inviteGroups', 'uses' => 'EventsController#inviteGroups'
]);
Route::get('events/{id}/duplicate', [
'as' => 'duplicate', 'uses' => 'EventsController#duplicate'
]);
Route::get('events/{id}/book', [
'as' => 'book', 'uses' => 'EventsController#book'
]);
Route::get('events/{id}/unbook', [
'as' => 'unbook', 'uses' => 'EventsController#unbook'
]);
Route::post('events/{id}/groups', [
'as' => 'addGroups', 'uses' => 'EventsController#addGroups'
]);
Route::post('events/{id}/helpers', [
'as' => 'addHelpers', 'uses' => 'EventsController#addHelpers'
]);
Route::resource('events', 'EventsController');
I'm having difficulty with the "book" route, which throws the following error when I hit it:
MethodNotAllowedHttpException in RouteCollection.php line 201:
The route users a function that attaches a user to an event, and then returns that user to the event page.
I'm sure its an order of precedence issue, but no matter how I organize the routes, I keep hitting that error. This is the only route on the list that's causing problems. Are there any best practices on route organization to fix this issue?
I have a user controller which returns users list, each user belongs to different group.
ex:- $groups = ['student_users' => 1, 'teacher_users' => 2, .....]
I can create routes such as below to access them
Route::get('users/{id}', [
'as' => 'user',
'uses' => 'Admin\UserController#listUser'
]);
But i want to create more user friendly or seo friendly say like this
Route::get('users/student', [
'as' => 'student',
'uses' => 'Admin\UserController#listUser'
]);
Route::get('users/teacher', [
'as' => 'teacher',
'uses' => 'Admin\UserController#listUser'
]);
Route::get('users', [
'as' => 'student',
'uses' => 'Admin\UserController#listUser'
]);//by default shows students list.
And i want to pass the id via route not via url. Whats the best way to do it.
do as following
Route::get('users/student', [
'as' => 'student',
'type' => 'student',
'uses' => 'Admin\UserController#listUser'
]);
in controller you can get type as below
public function listUser(\Illuminate\Http\Request $request)
$action = $request->route()->getAction();
dd($action['type']);
}
type is just an example. You can pass any variable.
I hope it helps.