Ad
ErrorException (E_NOTICE) Undefined Offset: 0 Laravel
I am trying to read from the database and display data into a form but I Keep getting this error.
This is my controller:
public function create()
{
/* this function gets data from the database (marks table) and render it to the view view */
$data['data']=DB::table('marks')->get();
if(count($data[0])>0){
return view('view',$data);
}
else{
return view('view');
}
}
And this is how I have defined the route:
Route::resource('claude', 'viewcontroller');
Ad
Answer
The variable $data
doesn't have an index of 0
.
But it has a key called data
.
So you have to access it via the key.
It should be
if(count($data['data']) > 0){
return view('view',$data);
}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → I can't do a foreign key, constraint error
- → Setting a default value on settings form return null in Octobercms
- → Eloquent Multitable query
- → "Laravel 5.1" add user and project with userId
- → Image does not go in database with file name only tmp name saved?
- → Database backup with custom code in laravel 5 and get the data upto 10 rows from per table in database
- → Trait 'IlluminateFoundationBusDispatchesJobs' not found
- → Setting the maxlength of text in an element that is displayed
- → laravel check between 2 integer from database
- → how to retrieve image from database in laravel 5.1?
- → relationship for database Column type object
- → Carousel in Laravel 4 does not show as expected
Ad