本文整理汇总了PHP中app\Photo::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Photo::create方法的具体用法?PHP Photo::create怎么用?PHP Photo::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Photo
的用法示例。
在下文中一共展示了Photo::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @param StorePhotoRequest $request
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
*/
public function store(StorePhotoRequest $request)
{
//TODO
// Find a safe way to getClientOriginalExtension()
//Construct file and path info
$file = $request->file('photo');
$ext = '.' . $file->getClientOriginalExtension();
$filename = time() . $ext;
$basePath = '/uploads/img/' . $filename;
$thumbPath = '/uploads/img/thumb/' . $filename;
$localPath = public_path() . $basePath;
$localThumbPath = public_path() . $thumbPath;
//DB info
$mimeType = $file->getClientMimeType();
$slug = Photo::generateUniqueSlug(8);
//Save the full image and the thumb to the server
$imageFull = Image::make($file->getRealPath())->save($localPath);
$imageThumb = Image::make($file->getRealPath())->widen(400)->save($localThumbPath);
//Create the DB entry
$imageStore = Photo::create(['path' => $basePath, 'thumb_path' => $thumbPath, 'mime_type' => $mimeType, 'slug' => $slug]);
if ($request->ajax()) {
return response()->json($imageStore);
} else {
return redirect()->route('home')->with(['global-message' => 'Uploaded!', 'message-type' => 'flash-success']);
}
}
示例2: test_a_photo_has_a_path
/**
* A basic test example.
*
* @return void
*/
public function test_a_photo_has_a_path()
{
$photo = Photo::create(['path' => '/storage/test.png']);
$photo = Photo::find(1);
$path = $photo->path;
$this->assertequals("/storage/test.png", $path);
}
示例3: register
/**
* Handle a registration request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function register(Request $request)
{
$validator = $this->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException($request, $validator);
}
$attributes = $request->only(array('username', 'first_name', 'last_name', 'description', 'email', 'tel_no', 'type', 'password'));
// Create user.
$user = $this->create($attributes);
if ($request->file('image')) {
//make timestamp and append username for filename
$timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
$imageFile = Input::file('image');
$mime = "." . substr($imageFile->getMimeType(), 6);
//move file to /public/images/
$filename = $timestamp . '-' . $user->username;
$photoData = array('fileName' => $filename, 'mime' => $mime);
$photo = Photo::create($photoData);
$imageFile->move(public_path() . '/images/uploads/', $filename . $mime);
//associate the image with the user
$user->photo_id = $photo->id;
$user->photo()->associate($photo);
}
$user->save();
// Send confirmation link.
return $this->sendConfirmationLink($user);
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @param OrganisationRequest $request
* @return \Illuminate\Http\Response
*/
public function store(OrganisationRequest $request)
{
/**
* If Photo is present then
*/
if ($request->hasFile('photo')) {
if ($request->file('photo')->isValid()) {
$photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension();
$request->file('photo')->move(public_path('images'), $photoName);
$photo = Photo::create(['url' => $photoName]);
$photoId = $photo->id;
} else {
return back()->withNotification('Error! Photo Invalid!')->withType('danger');
}
} else {
$photoId = null;
}
$slug = slug_for_url($request->name);
$details = empty($request->details) ? null : $request->details;
$initials = empty($request->initials) ? null : $request->initials;
$address = empty($request->address) ? null : $request->address;
if (Auth::check()) {
$request->user()->organisations()->create(['name' => $request->name, 'initials' => $initials, 'details' => $details, 'address' => $address, 'photo_id' => $photoId, 'slug' => $slug, 'user_ip' => $request->getClientIp()]);
} else {
$user = User::findOrFail(1);
$user->organisations()->create(['name' => $request->name, 'initials' => $initials, 'details' => $details, 'address' => $address, 'photo_id' => $photoId, 'slug' => $slug, 'user_ip' => $request->getClientIp()]);
}
return back()->withNotification('Organisation has been added!')->withType('success');
}
示例5: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
\Eloquent::unguard();
\DB::table('photos')->delete();
$faker = Faker\Factory::create();
for ($i = 0; $i < 50; $i++) {
Photo::create(array('project_id' => $faker->numberBetween(1, 50), 'photoUrl' => $faker->imageUrl(150, 150, 'city')));
}
}
示例6: savePhoto
public function savePhoto(Request $request)
{
$user = $request->get('CurrentUser');
if ($user != null) {
$photo64 = $request->json()->get('photo');
$newPhoto = Photo::create(['user_id' => $user->id, 'photo' => $photo64]);
return Response::json(['result' => 'success', 'photo' => $newPhoto->id], 200);
} else {
return Response::json(['result' => 'failed', 'message' => 'not authenticated']);
}
}
示例7: store
/**
* @param NewsRequest $request
* @return mixed
*/
public function store(NewsRequest $request)
{
if ($request->hasFile('photo')) {
if ($request->file('photo')->isValid()) {
$photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension();
$request->file('photo')->move(public_path('images'), $photoName);
$photo = Photo::create(['url' => $photoName]);
$slug = slug_for_url($request->title);
$request->user()->news()->create(['title' => $request->title, 'type' => $request->type, 'description' => $request->description, 'photo_id' => $photo->id, 'slug' => $slug]);
return back()->withNotification('News has been created!')->withType('success');
}
}
}
示例8: store
/**
* @param EventsRequest $request
* @return mixed
*/
public function store(EventsRequest $request)
{
if ($request->hasFile('photo')) {
if ($request->file('photo')->isValid()) {
$photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension();
$request->file('photo')->move(public_path('images'), $photoName);
$photo = Photo::create(['url' => $photoName]);
$slug = slug_for_url($request->name . ' ' . Carbon::parse($request->date)->diffForHumans());
$request->user()->events()->create(['name' => $request->name, 'date' => $request->date, 'description' => $request->description, 'venue' => $request->venue, 'photo_id' => $photo->id, 'slug' => $slug]);
return back()->withNotification('Event has been created!')->withType('success');
}
}
}
示例9: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(PhotoRequest $request)
{
if ($request->hasFile('photo')) {
if ($request->file('photo')->isValid()) {
$photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension();
$request->file('photo')->move(public_path('images'), $photoName);
$photo = Photo::create(['url' => $photoName, 'gallery' => 1]);
return back()->withNotification('Success! Image has been added to gallery.')->withType('success');
}
return back()->withNotification('Error! Something went wrong.')->withType('danger');
}
return back()->withNotification('Error! Something went wrong.')->withType('danger');
}
示例10: upload
public function upload(Request $request, $id)
{
$album = Album::findOrFail($id);
$files = $request->file();
$file = $files['files'][0];
if (!$file->isValid()) {
return new Response('Invalid Image ' . print_r($files, true), 400);
}
$destinationPath = app()->storagePath() . '/photos/';
$file->move($destinationPath, $file->getFilename());
$photo = Photo::create(['path' => $destinationPath . $file->getFilename(), 'name' => $file->getClientOriginalName(), 'album_id' => $album->id]);
$photoArray = $photo->toArray();
$photoArray['url'] = '/photo/' . $photo->id;
$photo->makeThumbnail();
return ['status' => 'done', 'files' => [$photoArray]];
}
示例11: store
/**
* Store a newly created resource in storage.
*
* @param TrophyRequest $request
* @return Response
*/
public function store(TrophyRequest $request)
{
$icon = $request->icon ? $request->icon : null;
$color = $request->color ? $request->color : null;
if ($request->hasFile('photo') && $request->file('photo')->isValid()) {
// Create name for new Image
$photoName = md5(Carbon::now()) . "." . $request->file('photo')->getClientOriginalExtension();
// Move image to storage
$image = Image::make($request->file('photo'));
$image->fit(500)->save(public_path('uploaded_images/') . $photoName);
$photo = Photo::create(['url' => $photoName]);
$request->user()->createTrophy()->create(['name' => $request->name, 'short_name' => $request->short_name, 'description' => $request->description, 'photo_id' => $photo->id, 'max_bearer' => $request->max_bearer, 'icon' => $icon, 'color' => $color]);
return back()->with('success', 'Trophy Created Successfully!');
}
return back()->with('error', 'Some Error in Form!')->withInput();
}
示例12: generate
protected function generate($year, $month)
{
HttpClient::init(['applicationId' => env('IMG_ID'), 'secret' => env('IMG_SECRET')]);
$date = Carbon::now();
$date->year = $year;
$date->month = $month;
$date->startOfMonth();
$end = $date->copy()->endOfMonth();
while ($date->lte($end)) {
$random = uPhoto::random();
$link = $random->links['html'];
$image = $random->urls['thumb'];
Photo::create(['date' => $date->toDateString(), 'link' => $link, 'image' => $image]);
$date->addDays(1);
}
return redirect('view/' . $year . '/' . $month);
}
示例13: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$images = Input::file('images');
$album_id = Input::get('album_id');
foreach ($images as $image) {
//$names[] = $image->getClientOriginalName();
$destinationPath = 'public/images';
// upload path
$fileName = $image->getClientOriginalName();
$image->move($destinationPath, $fileName);
// uploading file to given path
$image = Photo::create(['name' => $image->getClientOriginalName(), 'album_id' => $album_id]);
}
//dd($input);
//dd($input);
//$id = Input::get('album_id');
//$photo = Photo::create($input);
//$article->tags()->attach(Input::get('tag_list'));
return redirect('/');
}
示例14: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
*/
public function store(PhotoRequest $request)
{
// Create new photo
$photo = Photo::create(['title' => $request->get('title')]);
// Set image name as suglify title in lower case
$imageName = $photo->id . '.' . Str::slug($photo->title) . '.' . $request->file('image')->getClientOriginalExtension();
$imageName = Str::lower($imageName);
// Move file to storage location
$imagePath = storage_path() . '/uploads/img/';
$request->file('image')->move($imagePath, $imageName);
// Add image filename to model
$photo->update(['filename' => $imageName]);
// Fire event to resize photos
event(new PhotoSaved($photo));
/*
* Redirect to photos route with session
* of the updated entry
*/
return redirect()->route('dash.photos')->with(['flash_entry_updated' => true, 'flash_entry_id' => $photo->id, 'flash_entry_title' => $photo->title, 'flash_entry_route' => 'dash.photos.edit']);
}
示例15: create
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
if (isset($data['photo']) && $data['photo']->isValid()) {
$photoName = md5(Carbon::now()) . "." . $data['photo']->getClientOriginalExtension();
$image = Image::make($data['photo']);
$image->fit(300)->save(public_path('images/') . $photoName);
$photo = Photo::create(['url' => $photoName]);
$photoId = $photo->id;
} else {
$photoId = null;
}
/**
* Allow Insertion of Batch only if Submitter is Student
*/
$batch = $data['type'] == 0 ? $data['batch'] : null;
$user = User::create(['name' => $data['name'], 'email' => $data['email'], 'username' => $data['username'], 'password' => bcrypt($data['password']), 'gender' => $data['gender'], 'type' => $data['type'], 'college_id' => $data['college_id'], 'department_id' => $data['department_id'], 'photo_id' => $photoId, 'batch' => $batch, 'register_time_ip' => \Request::getClientIp()]);
/**
* EMAIL User a Welcome Email
* @TODO: Add this to a Queue and extract to a Event Listener
*/
/*$this->mailer->welcome($user);*/
/**
* Create Alumini
*/
if (isset($data['alumini'])) {
$slug = slug_for_url($data['name'] . ' of ' . $data['batch'] . '-' . $data['profession']);
$speech = empty($data['speech']) ? null : $data['speech'];
$facebook = empty($data['facebook']) ? null : $data['facebook'];
$organisation_id = empty($data['organisation_id']) ? null : $data['organisation_id'];
$user->aluminis()->create(['speech' => $speech, 'speaker' => $data['name'], 'batch' => $batch, 'department_id' => $data['department_id'], 'profession' => $data['profession'], 'organisation_id' => $organisation_id, 'photo_id' => $photoId, 'email' => $data['email'], 'facebook' => $facebook, 'slug' => $slug]);
}
\Session::flash('user.has.registered', true);
/**
*Subscribe this user to Weekly Newsletter
* @TODO: Enable this in production
*/
//Newsletter::subscribe($user->email);
return $user;
}