Reputation: 102
I'm trying to write a simple site that can write and read of a simple mysql database, using Laravel, but I've run into a full stop as Laravel doesn't seem to be recognising my model. Either that or I am doing something wrong.
My model:
class Submission extends Eloquent
{
public static $timestamps = true;
protected $fillable = array('location', 'twitter', 'instagram', 'website');
}
My form:
@extends('layout')
@section('content')
{{ Input::old('twitter') }} <br />
{{ Input::old('instagram') }} <br />
{{ Input::old('website') }} <br />
{{ Form::open(array('url' => '/submission', 'files' => true)) }}
<div class="form-group">
{{ Form::label('twitter', 'Twitter') }}
{{ Form::text('twitter', '', array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('instagram', 'Instagram') }}
{{ Form::text('instagram', '', array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('website', 'Website') }}
{{ Form::text('website', '', array('class' => 'form-control')) }}
</div>
{{ Form::button('Submit image', array('class' => 'btn btn-success', 'type' => 'submit')) }}
<input type="hidden" name="post" value="yes">
{{ Form::close() }}
@stop
My controller:
public function postView()
{
$submission = new Submission;
$submission->twitter = Input::get('twitter');
$submission->instagram = Input::get('instagram');
$submission->website = Input::get('website');
$submission->save();
return Redirect::to('submission')->withInput();
}
My database looks like: id location twitter instagram website created_at updated_at
I know that my database config is correct as I can retrieve information using DB::table('submissions')->get();
so from what I can tell it's Laravel that's not recognising my model?
EDIT:
Turns out that changing public static $timestamps = true;
to public $timestamps = true;
fixed it.
Upvotes: 1
Views: 2385
Reputation: 1857
Does this works :
DB::table('submissions')->get();
as it should return everything in the table. If it works then Eloquent can't find your table you can try to put that in your model:
protected $table = 'submissions';
It will define explicitly the table name in the model, even if it seems correct in your case
Otherwise you need to tell what exactly laravel answers when you made a request.
Hope it helps
Upvotes: 2