Level 88
You select based on the image and not on the user! Do you have a relation setup between the user and the image? How did you link the user to the image? You can do the inverse look up for your edit function ;)
i try to make user can edit there uploaded image but i want to edit image which belongs to only his/her. In my case user able to edit other image my controller
public function edit($id)
{
$image = Image::findOrFail($id);
return View::make('images.edit', compact('image'))->with('title', 'edit image');
}
help me!!
thanks!
You should connect the pictures to the user with sync, attach or detach here is an example:
public function create() {
$user = Auth::user();
$file = Input::file('image');
$picture = new Image;
$extension = $file->getClientOriginalExtension();
$sha1 = sha1($file->getClientOriginalName());
$filename=date('Y-m-d-h-i-s').".".$sha1.".".$extension;
$path = public_path('img/users/' . $filename);
$picture->path='img/users/' . $filename;
$picture->save();
// Add the connection between the image and the user
$user->images()->attach($picture->id);
}
public function edit($id) {
$user = Auth::user();
$picture = Image::findOrFail($id);
$file = Input::file('image');
if ($file)
{
// Remove the connection between the current image and the user
$user->images()->detach($picture->id);
// Do the same process as above for getting the image ready
// Then again use attach to connect the image and the user
}
}
Please or to participate in this conversation.