当前位置: 首页>>代码示例>>PHP>>正文


PHP Dog::save方法代码示例

本文整理汇总了PHP中Dog::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Dog::save方法的具体用法?PHP Dog::save怎么用?PHP Dog::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dog的用法示例。


在下文中一共展示了Dog::save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     // create the validator
     $validator = Validator::make(Input::all(), Dog::$rules);
     // attempt validation
     if ($validator->fails()) {
         Log::info('Validator failed', Input::all());
         Session::flash('errorMessage', 'Something went wrong please refer to the errors below:');
         // validation failed, redirect to the dog create page with validation errors and old inputs
         return Redirect::back()->withInput()->withErrors($validator);
     } else {
         $file = Input::file('img_url');
         $destinationPath = public_path() . '/img/dogs';
         $filename = $file->getClientOriginalName();
         Input::file('img_url')->move($destinationPath, $filename);
         if (Input::file('img_url2') != '') {
             $file2 = Input::file('img_url2');
             $destinationPath = public_path() . '/img/dogs';
             $filename2 = $file2->getClientOriginalName();
             Input::file('img_url2')->move($destinationPath, $filename2);
             $dog = new Dog();
             $dog->name = Input::get('name');
             $dog->comment = Input::get('comment');
             $dog->gender = Input::get('gender');
             $dog->banner = Input::get('banner');
             $dog->retired = Input::get('retired');
             $dog->puppy = Input::get('puppy');
             $dog->past = Input::get('past');
             $dog->sold = Input::get('sold');
             $dog->mom = Input::get('mom');
             $dog->dad = Input::get('dad');
             $dog->fun = Input::get('fun');
             $dog->img_url = $filename;
             $dog->img_url2 = $filename2;
             $dog->user_id = Auth::id();
             $dog->save();
             Session::flash('successMessage', 'Your dog was saved successfully');
             return Redirect::action('DogsController@create');
         }
         $dog = new Dog();
         $dog->name = Input::get('name');
         $dog->comment = Input::get('comment');
         $dog->gender = Input::get('gender');
         $dog->banner = Input::get('banner');
         $dog->retired = Input::get('retired');
         $dog->puppy = Input::get('puppy');
         $dog->past = Input::get('past');
         $dog->sold = Input::get('sold');
         $dog->mom = Input::get('mom');
         $dog->dad = Input::get('dad');
         $dog->fun = Input::get('fun');
         $dog->img_url = $filename;
         $dog->user_id = Auth::id();
         $dog->save();
         Session::flash('successMessage', 'Your dog was saved successfully');
         return Redirect::action('DogsController@create');
     }
 }
开发者ID:remington9,项目名称:quanwillbulldogs,代码行数:63,代码来源:DogsController.php

示例2: create

 public function create()
 {
     if (Request::isMethod('post')) {
         $name = Input::get('name');
         $age = Input::get('age');
         $breed = Input::get('type');
         $likes = Input::get('notes');
         $token = Input::get('token');
         $owner_id = Input::get('id');
         $picture = Input::file('picture');
         $validator = Validator::make(array('name' => $name, 'age' => $age, 'breed' => $breed, 'token' => $token, 'owner_id' => $owner_id, 'picture' => $picture), array('name' => 'required', 'age' => 'required|integer', 'breed' => 'required', 'token' => 'required', 'owner_id' => 'required|integer', 'picture' => 'required|mimes:jpeg,bmp,png'));
         if ($validator->fails()) {
             $error_messages = $validator->messages()->all();
             $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
             $response_code = 200;
         } else {
             $is_admin = $this->isAdmin($token);
             if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) {
                 // check for token validity
                 if (is_token_active($owner_data->token_expiry) || $is_admin) {
                     // Do necessary operations
                     // check if there's already a dog
                     $dog = Dog::where('owner_id', $owner_id)->first();
                     if ($dog === null) {
                         $dog = new Dog();
                     }
                     $dog->name = $name;
                     $dog->age = $age;
                     $dog->breed = $breed;
                     $dog->likes = $likes;
                     $dog->owner_id = $owner_data->id;
                     // Upload File
                     $file_name = time();
                     $file_name .= rand();
                     $ext = Input::file('picture')->getClientOriginalExtension();
                     Input::file('picture')->move(public_path() . "/uploads", $file_name . "." . $ext);
                     $local_url = $file_name . "." . $ext;
                     // Upload to S3
                     if (Config::get('app.s3_bucket') != "") {
                         $s3 = App::make('aws')->get('s3');
                         $pic = $s3->putObject(array('Bucket' => Config::get('app.s3_bucket'), 'Key' => $file_name, 'SourceFile' => public_path() . "/uploads/" . $local_url));
                         $s3->putObjectAcl(array('Bucket' => Config::get('app.s3_bucket'), 'Key' => $file_name, 'ACL' => 'public-read'));
                         $s3_url = $s3->getObjectUrl(Config::get('app.s3_bucket'), $file_name);
                     } else {
                         $s3_url = asset_url() . '/uploads/' . $local_url;
                     }
                     $dog->image_url = $s3_url;
                     $dog->save();
                     $owner = Owner::find($owner_data->id);
                     $owner->dog_id = $dog->id;
                     $owner->save();
                     $response_array = array('success' => true);
                     $response_code = 200;
                 } else {
                     $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405);
                     $response_code = 200;
                 }
             } else {
                 if ($is_admin) {
                     $response_array = array('success' => false, 'error' => 'Owner ID not Found', 'error_code' => 410);
                 } else {
                     $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
                 }
                 $response_code = 200;
             }
         }
     } else {
         //handles get request
         $token = Input::get('token');
         $owner_id = Input::get('id');
         $validator = Validator::make(array('token' => $token, 'owner_id' => $owner_id), array('token' => 'required', 'owner_id' => 'required|integer'));
         if ($validator->fails()) {
             $error_messages = $validator->messages()->all();
             $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401, 'error_messages' => $error_messages);
             $response_code = 200;
         } else {
             $is_admin = $this->isAdmin($token);
             if ($owner_data = $this->getOwnerData($owner_id, $token, $is_admin)) {
                 // check for token validity
                 if (is_token_active($owner_data->token_expiry) || $is_admin) {
                     $dog = Dog::find($owner_data->dog_id);
                     if ($dog) {
                         $response_array = array('success' => true, 'thing_id' => $dog->id, 'age' => $dog->age, 'type' => $dog->breed, 'notes' => $dog->likes, 'image_url' => $dog->image_url);
                         $response_code = 200;
                     } else {
                         $response_array = array('success' => false, 'error' => 'No Dogs Found', 'error_code' => 445);
                         $response_code = 200;
                     }
                 } else {
                     $response_array = array('success' => false, 'error' => 'Token Expired', 'error_code' => 405);
                     $response_code = 200;
                 }
             } else {
                 if ($is_admin) {
                     $response_array = array('success' => false, 'error' => 'Owner ID not Found', 'error_code' => 410);
                 } else {
                     $response_array = array('success' => false, 'error' => 'Not a valid token', 'error_code' => 406);
                 }
                 $response_code = 200;
             }
//.........这里部分代码省略.........
开发者ID:netGALAXYStudios,项目名称:ourmovingapp,代码行数:101,代码来源:DogController.php

示例3: createEnvDog

 protected function createEnvDog()
 {
     $dog = new Dog();
     $dog->name = 'Crush';
     $dog->comment = 'this is crush';
     $dog->gender = 'Male';
     $dog->img_url = 'crushBanner.jpg';
     $dog->user_id = '1';
     $dog->banner = 1;
     $dog->save();
     $dog = new Dog();
     $dog->name = 'Ariat';
     $dog->comment = 'this is Ariat';
     $dog->gender = 'Female';
     $dog->img_url = 'ariatBanner.jpg';
     $dog->user_id = '1';
     $dog->banner = 1;
     $dog->save();
     $dog = new Dog();
     $dog->name = 'Crush';
     $dog->comment = 'this is crush';
     $dog->gender = 'Male';
     $dog->img_url = '1.jpg';
     $dog->user_id = '1';
     $dog->banner = 0;
     $dog->puppy = 1;
     $dog->sold = 1;
     $dog->past = 1;
     $dog->save();
     $dog = new Dog();
     $dog->name = 'Hay';
     $dog->comment = 'this is hay';
     $dog->gender = 'Male';
     $dog->img_url = 'hay1.jpg';
     $dog->img_url2 = 'hay2.jpg';
     $dog->user_id = '1';
     $dog->banner = 0;
     $dog->puppy = 1;
     $dog->sold = 0;
     $dog->past = 0;
     $dog->dad = 'Crush';
     $dog->mom = 'Ariat';
     $dog->save();
     $dog = new Dog();
     $dog->name = 'Maple';
     $dog->comment = 'this is maple';
     $dog->gender = 'Female';
     $dog->img_url = 'maple1a.jpg';
     $dog->img_url2 = 'maple1b.jpg';
     $dog->user_id = '1';
     $dog->banner = 0;
     $dog->puppy = 1;
     $dog->sold = 0;
     $dog->past = 0;
     $dog->dad = 'Crush';
     $dog->mom = 'Ariat';
     $dog->save();
     $dog = new Dog();
     $dog->name = 'Pumpkin';
     $dog->comment = 'this is pumpkin';
     $dog->gender = 'Female';
     $dog->img_url = 'pumpkin1a.jpg';
     $dog->img_url2 = 'pumpkin1b.jpg';
     $dog->user_id = '1';
     $dog->banner = 0;
     $dog->puppy = 1;
     $dog->sold = 1;
     $dog->past = 0;
     $dog->dad = 'Crush';
     $dog->mom = 'Ariat';
     $dog->save();
     $dog = new Dog();
     $dog->name = 'Pecan';
     $dog->comment = 'this is Pecan';
     $dog->gender = 'Male';
     $dog->img_url = 'pecan1a.jpg';
     $dog->img_url2 = 'pecan1b.jpg';
     $dog->user_id = '1';
     $dog->banner = 0;
     $dog->puppy = 1;
     $dog->sold = 1;
     $dog->past = 0;
     $dog->dad = 'Crush';
     $dog->mom = 'Ariat';
     $dog->save();
     $dog = new Dog();
     $dog->name = 'dog';
     $dog->comment = 'this is dog';
     $dog->gender = 'Female';
     $dog->img_url = 'dogs.jpg';
     $dog->user_id = '1';
     $dog->banner = 0;
     $dog->puppy = 1;
     $dog->sold = 1;
     $dog->past = 1;
     $dog->fun = 1;
     $dog->save();
     $dog = new Dog();
     $dog->name = 'Nehi';
     $dog->comment = 'this is nehi';
//.........这里部分代码省略.........
开发者ID:remington9,项目名称:quanwillbulldogs,代码行数:101,代码来源:DogsTableSeeder.php


注:本文中的Dog::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。