I have a blade template that is a user creation form that calls a function of a controller that performs the user's insertion into the database.
This driver has a code like this (the code works and the user is inserted into the DB)
/**
* Parses, validate and create a new resource.
*
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function storeUser(Request $request)
{
$roles = Input::get('roles');
$validator = app('validator')->make($request->all(), [
'name' => 'bail|required|string',
'email' => 'bail|required|string',
'status'=> 'bail|boolean',
'created_at' => 'bail|datetime',
'created_by' => 'bail|integer',
]);
if ($validator->fails()) {
return $this->jsonValidatorFailedResponse($validator->errors());
};
$userCreated = User::create($data->toArray());
return $this->jsonCreatedResponse($userCreated);
}
Then I have the template that is the form from which the user enters the data that is how it is
@extends('layouts.app')
@section('title', trans('messages.User Create'))
@section('content')
<div id="semester-create" class="row">
<div class="col-md-12">
<div class="jumbotron">
<div class="row">
<div class="col-md-12">
<div id="section-title" class="h2">{{ trans('messages.User Create') }}</div>
</div>
</div>
<hr class="my-3">
<div id="section-body">
<form id="section-form" action="{{ route('admin.users.store') }}" method="post">
<div class="row">
<div class="col-md-6">
<label for="identifier">@lang('messages.name') *</label>
<input type="text" id="name" class="form-control" name="name" aria-describedby="name_help" data-validation="required" />
</div>
<div class="col-md-6 form-group">
<label for="qr_code">@lang('messages.email')</label>
<input type="text" id="email" class="form-control" name="email" aria-describedby="email_help" data-validation="required" />
</div>
<div class="col-md-6 form-group">
<label for="enabled_check">¿Activar usuario?</label>
<div id="enabled_check" class="form-check">
<input type="checkbox" id="status" class="form-check-input" name="status" value="1" aria-describedby="status_help">
<label class="form-check-label" for="enabled">@lang('messages.Enabled')</label>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<input class="btn btn-primary" type="submit" value="@lang('messages.Save')"/>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
@endsection
What it does is show a form where the user enters the data and makes a call to the function that I have previously set.
The previous function returns a JSON because the idea is to be able to reuse that method in other templates, so my question is from this template how can I make the POST do the action and capture the response of the function and can show something by screen or redirect.
Thanks