I wasn't quite sure how to format the name because I've done a bit of troubleshooting and still can't even narrow down quite what the issue is at the moment as to why the code I have isn't inserting a row into my SQL database. The code right now, which is located inside the EventController file, is as follows
public function create(Request $request){
$this->validate($request, [
'name' => ['required', 'unique:events', 'string', 'max:50'],
'event_desc_short' => ['required', 'string', 'max:120'],
'event_desc' => ['required', 'string'],
'event_free' => ['required', 'boolean'],
'event_low_cost' => ['nullable', 'numeric', 'between:0,9999.99', 'required_if:event_free,false'],
'event_high_cost' => ['nullable', 'numeric', 'between:0,999999.99', 'required_if:event_free,false'],
'event_featured' => ['required', 'boolean'],
'event_feature_type' => ['nullable', 'string', 'required_if:event_featured,true', Rule::in(['yearly', 'monthly', 'weekly'])],
'event_daily_budget' => ['nullable', 'required_if:event_featured,true', 'numeric', 'between:0,999999.99'],
'event_picture_link' => ['nullable'],
'location' => ['nullable'],
]);
$event = new Event;
$event->name = $request->input('name');
$event->event_desc_short = $request->input('event_desc_short');
$event->event_desc = $request->input('event_desc');
$event->event_free = $request->input('event_free');
$event->event_posting_business = Auth::id();
$event->event_low_cost = $request->input('event_low_cost');
$event->event_high_cost = $request->input('event_high_cost');
$event->event_featured = $request->input('event_featured');
$event->event_feature_type = $request->input('event_feature_type');
$event->event_daily_budget = $request->input('event_daily_budget');
$event->location = $request->input('location');
$event->save();
return redirect('/userlanding')->with('success', 'Created Event Successfully!');
}
And the Event model is as follows..
namespace App;
use Illuminate\Database\Eloquent\Model;
class Event extends Model
{
protected $table = 'events';
protected $fillable = [
"name", "event_desc_short" , "event_desc" , "event_free" , "event_low_cost" ,
"event_high_cost" , "event_featured" , "event_feature_type" , "event_daily_budget", "event_picture_link", "location"
];
}
And the form is as follows
{!! Form::open(['action' => 'EventController@create', 'method', 'POST']) !!}
<div class="form-group text-left">
{{Form::label('name', 'Event Name', ['class' => 'text-left'])}}
{{Form::text('name', '', ['class' => 'form-control'])}}
</div>
<div class="form-group text-left">
{{Form::label('event_desc_short', 'Event Description (Short)', ['class' => 'text-left'])}}
{{Form::text('event_desc_short', '', ['class' => 'form-control'])}}
<small class="form-text text-muted">A short description to catch viewer's attention</small>
</div>
<div class="form-group text-left">
{{Form::label('event_desc', 'Event Description (Full)', ['class' => 'text-left'])}}
{{Form::text('event_desc', '', ['class' => 'form-control'])}}
<small class="form-text text-muted">Full description to be viewed on viewing</small>
</div>
<div class="form-group text-left">
{{Form::label('event_free', 'Is this event free to attend?', ['class' => 'text-left'])}}
{{Form::select('event_free', ['true' => 'Yes', 'false' => 'No'], ['class' => 'form-control', 'onchange' => 'openCostPanel()'])}}
</div>
<div id="not-free-event-options">
<div class="row">
<div class="col">
<div class="form-group text-left">
{{Form::label('event_low_cost', 'Minimum Cost to attend Event')}}
{{Form::number('event_low_cost', 'value', ['class' => 'form-control'])}}
</div>
</div>
<div class="col">
<div class="form-group text-left">
{{Form::label('event_high_cost', 'Maximum Cost to attend Event')}}
{{Form::number('event_high_cost', 'value', ['class' => 'form-control'])}}
</div>
</div>
</div>
</div>
<div class="form-group text-left">
{{Form::label('event_featured', 'Would you like to feature this event?')}}
{{Form::select('event_featured', ['false' => 'No', 'true' => 'Yes'], ['class' => 'form-control', 'onchange' => 'openFeaturedPanel()'])}}
</div>
<div id="featured-event-options">
<div class="row">
<div class="col">
<div class="form-group text-left">
{{Form::label('event_feature_type', 'What type of featuring would you like?')}}
{{Form::select('event_feature_type', ['yearly' => 'Yearly', 'monthly' => 'Monthly', 'weekly' => 'Weekly'], ['class' => 'form-control'])}}
</div>
</div>
<div class="col">
<div class="form-group text-left">
{{Form::label('event_daily_budget', 'How much would you like to spend to be featured?')}}
{{Form::number('event_daily_budget', 'value', ['class' => 'form-control'])}}
<small class="form-text text-muted">Bid amount.</small>
</div>
</div>
</div>
</div>
<div class="form-group text-left">
{{Form::label('event_location', 'Event Address', ['class' => 'text-left'])}}
{{Form::text('event_location', '', ['class' => 'form-control'])}}
</div>
{{Form::submit('Create Event', ['class' => 'btn btn-primary'])}}
{!! Form::close() !!}
After looking carefully at my code for a long time, and searching through Stack Overflow, I seem to be missing something probably super minuet that is preventing it from submitting.
Weirder still, in an attempt to debug the error, I added a error message template which is supposed to display an error, which looks as follows
@if(count($errors) > 0)
@foreach($errors->all() as $error)
<div class="alert alert-danger">
{{$error}}
</div>
@endforeach
@endif
@if(session('success'))
<div class="alert alert-success">
{{session('success')}}
</div>
@endif
@if(session('error'))
<div class="alert alert-danger">
{{session('error')}}
</div>
@endif
This is included on the template with the form on it, and when submitting the form it redirects successfully to the page /userlanding but there is no message on it, of any type (error or success)
I'm super confused, as there doesn't seem to be any issues with the code as it is.