0

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.

4
  • could you share error message you get Commented Jan 18, 2020 at 19:42
  • In what? As I said nothing shows up from the error message file, I tried searching for error logs in the laravel folders but every logging file hasn't been updated for a couple days so nothing was reported to them. Commented Jan 18, 2020 at 19:44
  • Unrelated but try using $event = Event::create($request->all()); $event->event_posting_business = Auth::id(); $event->save(); Commented Jan 18, 2020 at 20:26
  • @JacobHyde Still didn't work. :/ Commented Jan 18, 2020 at 20:33

1 Answer 1

1

Try to set SESSION_DRIVER=file to get it work

Seems related

don't forget to clear config cache

php artisan config:clear

Edit

The validation rules

'event_free' => ['required', 'boolean'] // boolean means accepts 0 OR 1 ('true' OR 'false' values are considered as strings)

Same for 'event_featured' => ['required', 'boolean']

So you must update :

{{Form::select('event_free', ['1' => 'Yes', '0' => 'No'], ['class' => 'form-control', 'onchange' => 'openCostPanel()'])}}

{{Form::select('event_featured', ['0' => 'No', '1' => 'Yes'], ['class' => 'form-control', 'onchange' => 'openFeaturedPanel()'])}}
Sign up to request clarification or add additional context in comments.

8 Comments

The file input is a placeholder at the moment to insert into the database, I haven't setup all of the folders to allow for image uploads yet so I just have it being inserted as null, so the file configuration isn't the issue. I'll clear the config cache and see if anything appears.
Your problem is probably with validation function. According to Denislav Karagiozov response here (stackoverflow.com/questions/59614407/…): "when a form submits a huge portion of content, such as like 2 paragraphs of text, the form input is sent to a cookie in order to flash the errors when the validation fails. But since the input contains a lot of text, the validation fails, but the error flash also fails, silently,and $errors is left empty."
SESSION_DRIVER=file and Setup folders for image uploads are different things
I did as such, but there still isn't anything returning as an error
Your app is running on top of Laravel 6 ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.