Undefined variable: statuses (View: /Users/domlanza/code/kermode/resources/views/timeline/index.blade.php)

Multi tool use
Undefined variable: statuses (View: /Users/domlanza/code/kermode/resources/views/timeline/index.blade.php)
I am getting this message and going a little crazy. Here is my code please just try to point me in the right direction it would be greatly appreciated.
timeline.index.blade.php
@extends('layouts.app')
@section('content')
has('status') ? ' has-error' : ''}}">
getFirstNameOrUsername() }} ?" name="status"
class="form-control" rows="2">
@if ($errors->has('status'))
{{ $errors->first('status') }}
@endif
<button type="submit" class="btn btn-default">Update status</button>
<input type="hidden" name="_token" value="{{ Session::token() }}">
</form>
<hr>
</div>
</div>
@if (!$statuses->count())
There's nothing in your timeline, yet.
@else
@foreach ($statuses as $status)
![]()
Dayle
It's a lovely day today.
- 2 days ago
- Like
- 10 Likes
![]()
</div> -->
<form role="form" action="#" method="post">
<input type="submit" value="Reply" class="btn btn-default btn-sm">
</form>
</div>
</div>
@endforeach
@endif
</div>
</div>
@endsection
Status.php
<?php
namespace Kermode;
use IlluminateFoundationAuthUser as Authenticatable;
class Status extends Authenticatable
{
protected $table = 'statuses';
protected $fillable = ['body'];
public function user()
{
return $this->belongsTo('Kermode', 'user_id');
}
}
StatusController.php
<?php
namespace KermodeHttpControllers;
use Auth;
use KermodeUser;
use IlluminateHttpRequest;
class StatusController extends Controller
{
public function postStatus(Request $request)
{
$this->validate($request, ['status' => 'required',
]);
Auth::user()->statuses()->create(['body' => $request->input('status'),
]);
return redirect()
->route('home')
->with('info', 'Status poseted.');
}
}
HomeController.php
<?php
namespace KermodeHttpControllers;
use IlluminateHttpRequest;
use Auth;
use KermodeStatus;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return IlluminateHttpResponse
*/
public function index()
{
if(Auth::check()) {
$statuses = Status::where(function($query) {
return $query->where('user_id', Auth::user()->id)
->orWhereIn('user_id', Auth::user()->friends()->pluck('id')
);
})
->orderBy('created_at', 'desc')
->paginate(10);
return view('timeline.index')
->with('statuses, $statuses');
}
return view('home');
}
}
This community is awesome and I appreciate all they do for others.
xxxx xxxxxx xxxxxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx
$statuses
we would need to see the controller method that is returning that view (
timeline.index
) to be able to take a step in a helpful direction– lagbox
Jul 2 at 2:51
timeline.index
@lagbox I just put up the home controller
– Dom L
Jul 2 at 2:53
3 Answers
3
You are not passing a variable statuses
to the view.
statuses
'statuses, $statuses'
'statuses, $statuses'
->with('statuses, $statuses');
'statuses'
'statuses'
->with('statuses', $statuses);
In HomeController.php Try to like this,
return view('timeline.index',compact('statuses'));
send data like this way
return view('timeline.index',compact('statuses'));
if you will send data using with it react as session data.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You dumped a lot of irrelevant code here. Please read about how to create a Minimal, Complete, and Verifiable example. But in what you posted, I don’t see anywhere that you defined
$statuses
, so this error seems pretty self-explanatory.– Ed Cottrell
Jul 2 at 2:08