here, i retrieve two tables to be displayed on one view page. the images is in the users table. when i clicked profile tab, it displayed error message : Trying to get property of non-object. what are wrong with my codes referring to the error message.
upload.blade.php
<div id="templatemo_sidebar">
<tr>
<div id="login">logged in as :</div>
</tr>
@foreach($users as $users)
<div id="img">
<img src="{!! '/profiles/'.$users->filePath !!}">{{$users->filePath}}
</div>
@endforeach
{!! Form::open(['action'=>'ProfileController@store', 'files'=>true]) !!}
<div class="form-group">
{!! Form::label('image', 'Choose an image') !!}
{!! Form::file('image') !!}
</div>
<div class="form-group">
{!! Form::submit('Save', array( 'class'=>'btn btn-danger form-control' )) !!}
</div>
{!! Form::close() !!}
@foreach($profiles as $profile)
<div id="profile_sidebar">
<tr>
<td>{{$profile->student_name}}</td>
</tr>
<tr>
<td>{{$profile->student_id}}</td>
</tr><br>
<tr>
<td>{{$profile->student_ic}}</td>
</tr>
<tr><br>
<td><mark>Status : {{$profile->status}}</mark></td>
</tr>
@endforeach
</div>
ProfileController.php
public function store(Request $request)
{
$users = Auth::user();
if($request->hasFile('image')) {
$file = Input::file('image');
//getting timestamp
//$timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
//$name = $timestamp. '-' .$file->getClientOriginalName();
$name=$file->getClientOriginalName();
$users->filePath = $name;
$file->move(public_path().'/profiles/', $name);
}
$users->save();
$users = Auth::user();
$users = Profile::where('student_id', $users->student_id)->get();
$profiles = Profile::all();
return view('profile', compact('users', 'profiles'));
}
}
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1TrmiVt
via IFTTT
Aucun commentaire:
Enregistrer un commentaire