I am facing a problem while fetching the data from database
view.php
<p>attend</p>
#foreach($attendings as $attending)
#if ($attending->acceptance==1)
{{ $attending->membername }}
#endif
#endforeach
<p>not attend</p>
#foreach($attendings as $attending)
#if ($attending->acceptance==0)
{{ $attending->membername }}
#endif
#endforeach
<br>
<br>
<p>final decision </p>
{{ $attendings->editor_com }}
controller
public function attendx()
{
$attendings = DB::table('attendance')->get();
return view('My_Work.report', ['attendings' => $attendings]);
}
routes
get('/editor/report','DatabaseController#attendx');
But what I'm facing is Undefined variable: attendings
What am I doing wrong?
Note: I am writing the codes in laravel 5.1
You are returning attendings to this view file My_Work.report.blade.php
So you have to place all your code in report.blade.php file .
Remove this line
{{ $attendings->editor_com }}
because this will throw error Trying to get property of non-object
Related
I try to ech the object of a laravel many-to-many relation in blade:
When I try to find the created_at with $product->id=47 and echo it out like so:
{{ $inquiry->products->find($product->id)->created_at }}
I get the error: "Trying to get property 'created_at' of non-object..."
When I remove the $product->id and change it to "47" everything works find:
{{ $inquiry->products->find(47)->created_at }}
But I need to query with the variable $product->id.
Any ideas what's wrong here?
Here is a longer part of my code:
#foreach ($upgrades as $upgrade)
{{ $upgrade->id }} //Echos exactly as 47
//List all upgrades
<select>
#if($inquiry->products->where('id', $upgrade->id)->count() == 1)
<option> {{ $inquiry->products->find($upgrade->id)->pivot->duration }}
#endif
</select>
#endforeach
When I try to use $student->links() I see this error :
Facade\Ignition\Exceptions\ViewException
Call to undefined method App\Student::links()
I checked the controller, model etc but all of them seem OK... How can I fix this?
(I tried this code both on my Macbook and VPS -CentOS7- but same problem occurs)
That part of my view looks like this:
</tr>
#endforeach
</tbody>
</table>
{{ $student->links() }}
</div>
#endsection
Change
{{ $student->links() }}
to
{{ $students->links() }}
(use plural form).
You need to paginate in your backend code. $students = App\Student::paginate(15);
And then you can access the links()
<div class="container">
#foreach ($students as $student)
{{ $student->name }}
#endforeach
</div>
{{ $students->links() }}
I am fetching records with pagination. The first page is working fine but when I click on page number 2 then it return following error
Undefined offset: 0
I am trying following script in controller
$Jobs = Jobs::orderBy('job_id', 'asc')->paginate(5);
return view('veteran.job-posting.index',['Jobs'=>$Jobs]);
In the blade following code I am trying
#if($Jobs)
#foreach($Jobs as $Job)
{{ ucfirst(trans($Job->job_title)) }}
#endforeach
#endif
For pagination I am using following script
<div class="pagination-test">
{{ $Jobs->links() }}
</div>
Please guide me why it does returning error when I click on page number 2. I would like to appreciate
After Request For More Detail from #pseudoanime
For more detail about error
2/2) ErrorException
Undefined offset: 0 (View: E:\xampp\htdocs\project\project-sub-root\resources\views\index.blade.php)
Try adding this outside of the loop
{{ $Jobs->links() }}
Can you try to add Pagination like this.
#if(count($Jobs) > 0)
#foreach($Jobs as $Job)
{{ ucfirst(trans($Job->job_title)) }}
#endforeach
{{ $Jobs->links() }}
#endif
With your CSS class
#if(count($Jobs) > 0)
#foreach($Jobs as $Job)
{{ ucfirst(trans($Job->job_title)) }}
#endforeach
<div class="pagination-test">
{{ $Jobs->links() }}
</div>
#endif
Edited Update
Try With With in controller
return view('veteran.job-posting.index')->with('Jobs',$Jobs);
Update your controller's function return and use compact function for to pass jobs to view.
$jobs = Job::orderBy("id", "asc")->paginate(5);
return view("jobs", compact("jobs"));
You need to add this for pagination in blade.
<ul class="pagination" >
{!! $Jobs->render() !!}
</ul>
I'm using Laravel 5.2 and returning an array result set to my view by using the following
return view('home')->with('devices', $devices)
I've attempted to loop through my array data by using the following in blade
#foreach($devices as $device)
{{ $device[name] }} has
{{ $device[views] }}
#endforeach
Using $device[name] throws Use of undefined constant name - assumed 'name'
I've also tried looping through the result like this
#foreach($devices as $device)
{{ $device->name }} has
{{ $device->views }}
#endforeach
You are sending it like constant not as string. Replace it like this:
#foreach($devices as $device)
{{ $device['name'] }}
{{ $device['views'] }}
#endforeach
I am trying to update information in my database with Laravel. Not sure what I am doing wrong but I can't seem to find where the problem is. Here is the code for my edit page (This is the page where I would edit information taken from my DB).
{{ Form::open(['url'=>'portfolio/update']) }}
<div>
{{ Form::label('portfolio_title', 'Portfolio Title:') }}
{{ Form::text('portfolio_title',$work->portfolio_title) }}
{{ $errors->first('portfolio_title','<span class="error">:message</span>') }}
</div>
<div>
{{ Form::label('portfolio_description', 'Portfolio Description') }}<br>
{{ Form::textarea('portfolio_description', $work->portfolio_description, ['size' => '50x5']) }}
{{ $errors->first('portfolio_description','<span class="error">:message</span>') }}
</div>
<div>
{{ Form::label('portfolio_content', 'Portfolio Content') }}<br>
{{ Form::textarea('portfolio_content', $work->portfolio_content, ['size' => '50x5']) }}
{{ $errors->first('portfolio_content','<span class="error">:message</span>') }}
</div>
{{ Form::hidden('id',$work->id) }}
<div>
{{ Form::submit('Update Work') }}
</div>
{{ Form::close() }}
I have a controller called PortfolioController that will save info to database and what not.
public function edit($work_title){
$work = Portfolio::wherePortfolio_title($work_title)->first();
return View::make('portfolio/edit', ['work' => $work]);
}
public function update(){
$id = Input::get('id');
$input = Input::except('id');
if( !$this->portfolio->fill($input)->isValid()){
return Redirect::back()->withInput()->withErrors($this->portfolio->errors);
}
$work = Portfolio::find($id);
$work->portfolio_title = Input::get('id');
$work->save();
}
Here is my route that I am working with:
Route::resource('portfolio','PortfolioController');
Route::post('portfolio/update','PortfolioController#update');
I am able to get the form populated with the correct information but when i change something like the title and click update, the page reloads but does not save in the DB. Sometimes I will get an MethodNotAllowedHttpException error. This has been pretty frustrating for me so any help will be greatly appreciated.
Why don't you just actually use your resource route?
First, remove the portfolio/update route. You don't need it.
Then change your Form::open to this:
{{ Form::open(['route' => ['portfolio.update', $work->portfolio_title], 'method' => 'put']) }}
This way you target the update method in your RESTful controller.
Finally change that to use the portfolio_title as identifier and you should be able to remove the hidden id field from your form.
public function update($work_title){}
Please take a look at:
RESTful controllers
Opening a form