MattB
2 months ago
181
4
Laravel

Cannot send to store method from controller

Posted 2 months ago by MattB

I have a form inside a modal which isn't talking to the store method of the controller it's sent to. When I move the form outside of the modal to the page that calls the modal, it works fine and I can post to the store method. Can't see what the issue is here. It doesn't matter if I use a custom request or the basic one for validation:

Form Modal:

<div class="modal-body">
        <form>
          <div class="row">
            <div class="col-12">
              {!! Form::open(['method' =>'POST', 'action'=> '[email protected]']) !!} 
              <div class="form-group {{$errors->has('date') ? 'has-error' : ''}}">
                {!! Form::label('date', 'News Flash Date:') !!}
                {!! Form::text('date', null, ['class'=>'form-control'])!!}
                @if($errors->has('date'))
                  {{$errors->first('date')}}
                @endif
              </div>
              <br>
              <div class="form-group">
                {!! Form::submit('Add News Flash', ['class'=>'btn btn-primary']) !!}
              </div>
              {!! Form::close() !!}
            </div>            
          </div>         
        </form>
      </div>

Store Method:

public function store(NewsFlashRequest $request)
    {
        dd($request);
        $newsFlash = new Newsflashes();          
          $newsFlash->date = $request->date;
          $newsFlash->published = 0;          
          $newsFlash->number_of_stories = 0;          
          $newsFlash->save();
          return redirect()->route('admin.newsflash.index');
    }

Route:

Route::resource('/admin/newsflashes', 'AdminNewsFlashController', [
  'names'=>[
  'index'=>'admin.newsflashes.index',
  'create'=>'admin.newsflashes.create',
  'store'=>'admin.newsflashes.store',
  'edit'=>'admin.newsflashes.edit',
  'show'=>'admin.newsflashes.show',
  'destroy'=>'admin.newsflashes.destroy',
  ]]);

From the route list:

 POST      | admin/newsflashes                  | admin.newsflashes.store       | App\Http\Controllers\[email protected]                    | web

Please sign in or create an account to participate in this conversation.