phplaravellaravel-bladelaravel-controllerlaravel-datatables

Neither it show an error nor save the Data into my database PHP Laravel?


I am trying to insert data into the database neither it shows an error nor saves the data into my database below are the codes. here is the create blade php page .

@extends('layouts.app')

@section('content')


<h1>Create a Camp</h1>

<!-- if there are creation errors, they will show here -->
{{ HTML::ul($errors->all()) }}

{{ Form::open(array('url' => 'camps')) }}


    <div class="form-group">
        {{ Form::label('name', 'Name') }}
        {{ Form::text('name', Request::old('name'), array('class' => 'form-control')) }}
    </div>

     <div class="form-group">
        {{ Form::label('district', 'District') }}
        {{ Form::text('district', Request::old('district'), array('class' => 'form-control')) }}
    </div>

     <div class="form-group">
        {{ Form::label('address', 'Address') }}
        {{ Form::text('address', Request::old('address'), array('class' => 'form-control')) }}
    </div>

     <div class="form-group">
        {{ Form::label('block', 'Block') }}
        {{ Form::text('block', Request::old('block'), array('class' => 'form-control')) }}
    </div>

     <div class="form-group">
        {{ Form::label('population', 'population') }}
        {{ Form::text('population', Request::old('population'), array('class' => 'form-control')) }}
    </div>


    {{ Form::submit('Create the Camp!', array('class' => 'btn btn-primary')) }}

{{ Form::close() }}

@endsection

here is the controller the index controller works fine when I manually enter the data it fetches from the database here is the store controller and also it not validate the forms data , i am new i dont know how to do it

  public function store(Request $request)
    {
        $rules = array(
            'name'    => 'required',
            'district'=> 'required',
            'address' => 'required',
            'block'   => 'required|numeric',
            'Population'   => 'required|numeric',
        );
        $validator = Validator::make(Request::all(), $rules);
        if ($validator->fails()) {
            return Redirect::to('camp/create')
                ->withErrors($validator)
                ->withRequest(Request::except('password'));
        } else {
            // store
            $camp = new Camp;
            $camp->name       = Request::get('name');
            $camp->district      = Request::get('district');
            $camp->address = Request::get('address');
            $camp->block      = Request::get('block');
            $camp->population = Request::get('population');
            $camp->save();

            // redirect
            Session::flash('message', 'Successfully created Camp!');
            return view('camp\camps',['camps'=>$camps]);
        }
    }

Solution

  • You forgot to add parenthesis after Camp it should be like this:

    $camp = new Camp();
    $camp->name       = $request->name;
    $camp->district   = $request->district;
    $camp->save();