When i create the function on controller to show with method 'index' and add this route on my web.php works, but when try the form, with post method to 'login', Laravel alert me on my browser: Route [samein.login] not defined. What is my mistake? I'm new on Laravel, and not understand completely: ¿What is my error? Controller:
<?php
namespace App\Http\Controllers;
use App\Http\Requests\loginrequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
use Illuminate\Queue\RedisQueue;
class logincontroller extends Controller
{
public function index(){
return view('login');
}
public function login( )
{
$credentiales = $request->getCredentials();
if( Auth::validate($credentiales) ){
return redirect()->to('login')->withErrors('auth.failed');
}
$user = Auth::getProvider()->retrieveByCredentials($credentiales);
Auth::login($user);
return $this->authenticated($request,$user);
}
public function authenticated (Request $request,$user){
return redirect('accountModule.indexusers');
}
}
Route on web.php :
Route::resource('/samein',logincontroller::class);
Template:
@extends('components\header')
<section >
<div >
<div >
<div >
<img src="{{ URL::asset('img/logo.png') }}"
height="500">
</div>
<div >
<form action="{{ route('samein.login') }}" method="POST">
@csrf
<!-- Email input -->
<div >
<input type="email" name="username"
placeholder="Enter a valid email address" />
<label for="form3Example3">Usuario</label>
</div>
<!-- Password input -->
<div >
<input type="password" name="password"
placeholder="Enter password" />
<label for="form3Example4">Contraseña</label>
</div>
<div >
<button type="button"
style="padding-left: 2.5rem; padding-right: 2.5rem;">Iniciar Sesión</button>
</div>
</form>
</div>
</div>
</div>
</section>
[enter image description here][1] [1]: https://i.stack.imgur.com/trktp.png
CodePudding user response:
Resource controllers have default route names assigned to them by Laravel.
Instead of:❌
{{ route('samein.login') }}
Use this:✅
{{ route('samein.store') }}
Actions Handled By Resource Controller
POST
|/photos
|store
|photos.store
Addendum
By default, all resource controller actions have a route name; however, you can override these names by passing a
names
array with your desired route names:
use App\Http\Controllers\LoginController; Route::resource('samein', LoginController::class)->names([ 'store' => 'samein.login' ]);