本文整理匯總了PHP中app\Photo::with方法的典型用法代碼示例。如果您正苦於以下問題:PHP Photo::with方法的具體用法?PHP Photo::with怎麽用?PHP Photo::with使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Photo
的用法示例。
在下文中一共展示了Photo::with方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$photo = Photo::find($id);
if (!$photo || count($photo)) {
throw new NotFoundHttpException('no photo found');
}
$photo = App\Photo::with(['post', 'post.post_author', 'post.comments'])->where('id', $id)->get();
return response()->json($photo);
}
示例2: getIndex
/**
* Show the parter list to the user.
*
* @return Response
*/
function getIndex()
{
$set = DataSet::source(Photo::with('Object'));
$set->link(url('/photo/edit'), '', 'show');
$set->link(url('/photo/edit'), "anlegen", "TR");
$set->paginate(10);
$set->build();
return view('set.photo', compact('set'));
}
示例3: postEdit
public function postEdit($id, Request $request)
{
$photo = Photo::with('tags')->find($id);
if (!$photo) {
return redirect()->back()->withError('Photo not found.');
}
$validation = Validator::make($request->all(), ['title' => 'required|min:3', 'photo' => 'image', 'user_id' => 'required|integer|exists:users,id', 'tags' => 'required']);
if ($validation->fails()) {
return redirect()->back()->withInput()->withErrors($validation);
}
$isFileUploaded = $request->hasFile('photo');
if ($isFileUploaded) {
//First, delete the old photos and all sizes using Croppa
Croppa::delete(public_path() . '/uploads/' . $photo->image);
//Then Upload the image and return the filename
$upload = Photo::upload($request->file('photo'));
}
//Tag Stuff
//First, create(if needed) and return IDs of tags
$tagIds = Tag::createAndReturnArrayOfTagIds($request->get('tags'));
//If user wants to read the tags (keywords) from the file, then we need to fetch them from uploaded file.
if ($isFileUploaded && $request->has('read_tags_from_file')) {
$exif = exif_read_data($upload['fullpath'], 'ANY_TAG', true);
if ($exif) {
if (array_key_exists('IFD0', $exif)) {
if (array_key_exists('Keywords', $exif['IFD0'])) {
//array_unique, because same tags may be on both the form and the file, but only one is added to the database
//Keywords are delimited by semicolon ( ; ) in the tag data.
$tagIds = array_unique(array_merge($tagIds, Tag::createAndReturnArrayOfTagIds($exif['IFD0']['Keywords'], ';')));
}
}
}
}
//Tag Stuff end
$photo->user_id = $request->get('user_id');
$photo->title = $request->get('title');
if ($isFileUploaded) {
$photo->image = $upload['filename'];
}
$photo->save();
//Now, sync all the associated tags
$photo->tags()->sync($tagIds);
return redirect()->back()->withSuccess('Photo updated successfully!');
}
示例4: getDetail
public function getDetail($photoSlug)
{
$photo = Photo::with('tags', 'user')->whereSlug($photoSlug)->first();
if (!$photo) {
return redirect('/')->withError('Photo not found');
}
return view('photos.detail')->withPhoto($photo);
}