I am new to web development and have been learning Laravel. I am following a video tutorial series (https://laracasts.com/series/laravel-5-from-scratch). In the series they use a text are to pass data to a post controller. I would like the user to input their name. If they are in the database, then they are taken to a user's page. I have the Model, database, and migrations working.
For the index page, routing:
Route::get('/','UserController@index');
Route::get('/user', UserController@checked');
Route::get('/accesdenied','UserController@accessdenied');
index view:
<h1>Welcome</h1>
<h1>Please enter User Name</h1>
<form>
<div>
<textarea name="body"></textarea>
<button type="submit">Access</button>
</div>
</form>
controller:
class UserController extends Controller
{
public function index()
{
return view('users.index');//view is in users folder
}
public function check(Request $request)
{
$user = DB::table('users')->where('name', $request->body)->first();
if (isset($user))
return view(‘users.checked’, compact(‘user’));
else
return view('users.accessdenied');//is it right to direct to a page back to a controller?
}
public function accessdenied(Request $request)
{
//try again is same as index page with text added
return view('users.tryagain');
}
}
I have no idea what to pass from the form.
Thank you.