Support the ongoing development of Laravel.io →
Configuration Authentication Security
Last updated 2 years ago.
0

I'd get used to using controllers:

Route::get('login', array('uses' => 'AuthController@getLogin'));
Route::get('word you want to use to invoke this', array('uses' => 'controller@method'));

Or a post controller. There are times for a simple function, or redirect in route, but for main databasing using eloquent, and passing results to views, you need controllers.

Last updated 2 years ago.
0

Thanks for answering. I tried to edit my post because I didn't quite make it a clear posting, but I get an error while trying to save the edited post.

I do use controllers, but only after routing, like your example. But what I didn't make clear is that I see a lot of code examples in which for example a form submit its result directly to a controller, without a route. And this is what I do not understand. I do not want a user to be able to fabricate an url which directly goes to a function in a controller, I first want the checks in the route.

Last updated 2 years ago.
0

I am new to blade, so ignore my bad blade. I am going to use sections later, this is to show the router.

<!doctype html>
<html>
<head>
	<title>Look at me Login</title>
</head>
<body>

	{!! Form::open(array('url' => 'loggin')) !!}
		<h1>Login</h1>

		<!-- if there are login errors, show them here -->
                @if (Session::get('loginError'))
		<div class="alert alert-danger">{!! Session::get('loginError') !!}</div>
		@endif

		<p>
			{!! Form::label('userid', 'userid') !!}
			{!! Form::text('userid', Input::old('userid'), array('placeholder' => '#')) !!}
		</p>

		<p>
			{!! Form::label('password', 'Password') !!}
			{!! Form::password('password') !!}
		</p>

		<p>{!! Form::submit('Submit!') !!}</p>
	{!! Form::close() !!}

</body>
</html>

The line

{!! Form::open(array('url' => 'loggin')) !!}

I have this route:

Route::post('loggin', array('uses' => 'AuthController@postLogin'));

So in the view, when you submit the form it's not going direct to controller, it is still routed. The whole login process would involve
A route to get you to the login form:

Route::get('login', array('uses' => 'AuthController@getLogin'));

That controller method takes you to the view:

public function getLogin()
	{
		return view('user.login');
	}

Once login form is filled out it's posted but goes through:

Route::post('loggin', array('uses' => 'AuthController@postLogin'));

Which enacts this code in controller:

public function postLogin(LoginRequest $request)
        {
	    $tvar = $request->input('userid');
            $pw = $request->input('password');
            if ($this->auth->attempt(['userid' => $tvar, 'password' => $pw]))
		{
                    echo 'logged in';
                    //return redirect('olist');
		}
                echo 'ac===='. $this->auth->check().'====';
                if ($this->auth->check())
                {
                    echo 'The user is logged in...';
                    return redirect('pets');
                }
                else {
                    echo 'The user is NOT logged in...';
                }

		//return redirect('/auth/login')->withErrors([
			//'email' => 'These credentials do not match our records.',
		//]);
	}

This is laravel 5 code, laravel 4 a little different. But hopefully you can see the form post is going through router to get to controller. So yes everything goes through router.

Last updated 2 years ago.
0

Thanks again, really appreciate this.

Your example I understand, and thats also what I like. But in the documentation I see this example:

<form action="{{ action('RemindersController@postRemind') }}" method="POST">
    <input type="email" name="email">
    <input type="submit" value="Send Reminder">
</form>

And this scares me a little, because it looks like in this case the POST will never pass the router?

Last updated 2 years ago.
0

Never routed through a form maybe possible in laravel read this:
http://stackoverflow.com/questions/20340142/laravel-4-form-post

Last updated 2 years ago.
0

I still don't see if you use a form submit with a 'controller@function' action, if this goes via routes. The stack post also doesn't make it clear.

Last updated 2 years ago.
0

Have you tried it? Just make up a controller method, and a form with one field and try posting it just see if it works. I like to always pass through a route in mvc.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

dionmes dionmes Joined 24 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.