本文整理汇总了PHP中app\Product::Create方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::Create方法的具体用法?PHP Product::Create怎么用?PHP Product::Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Product
的用法示例。
在下文中一共展示了Product::Create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$input = $request->all();
//http://laravel.com/docs/5.0/validation#controller-validation
//Fazer a validacao dos campos
$this->validate($request, ['nome' => array('required', 'max:255'), 'categoria' => 'required', 'especificacao' => 'required | max:255', 'preco' => array('required', 'regex:/^\\d*[0-9](|,\\d*[0-9])?$/'), 'qtdEstoque' => 'required | numeric']);
Product::Create($input);
return redirect()->route('ListProduto');
// return redirect('admin/produtos');//retorna pra pagina de listagem de produtos
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
/*
$product = new Product;
$product->name = $request->name;
$product->price = $request->price;
$product->save();
*/
$inputs = $request->all();
$product = Product::Create($inputs);
return redirect()->action('ProductController@index');
//return redirect()->route('product.index');
}
示例3: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
// $this->call('UserTableSeeder');
//Member::Create(['username' => 'louis', 'password'=>'pw','secretquestion'=>'Where is your birth place?','secretanswer'=>'Hong Kong']);
Member::Create(['username' => 'admin',
'password'=>'admin',
'secretquestion'=>'Where is your birth place?',
'secretanswer'=>'Hong Kong']);
/*Category::Create ([
'name' => 'Nature'
]);
Category::Create ([
'name' => 'Architecture'
]);
Category::Create ([
'name' => 'People'
]);
Category::Create ([
'name' => 'Tech'
]);
Category::Create ([
'name' => 'Animals'
]);
$faker = Faker::create();
for ($i=0; $i<100; $i++){
$title = '';
$detail = $faker->realText(450,2);
$hadstock = true;
$slug = $title;
$publisher = $faker->name();
$company = $faker->company();
$price = 0.0 + Rand(1,60000) / 100;
$cid = 0;
$imgsrc = 'http://placeimg.com/268/249/'.'nature'.'/'.Rand(1,100);
switch (Rand(0,4)){
case 0:
$cid = 1;
$imgsrc = 'http://placeimg.com/268/249/'.'nature'.'/'.Rand(1,100);
break;
case 1:
$cid = 2;
$imgsrc = 'http://placeimg.com/268/249/'.'arch'.'/'.Rand(1,100);
break;
case 2:
$cid = 3;
$imgsrc = 'http://placeimg.com/268/249/'.'people'.'/'.Rand(1,100);
break;
case 3:
$cid = 4;
$imgsrc = 'http://placeimg.com/268/249/'.'tech'.'/'.Rand(1,100);
break;
case 4:
$cid = 5;
$imgsrc = 'http://placeimg.com/268/249/'.'animals'.'/'.Rand(1,100);
break;
}
$maxTitle = Rand(1,5);
for ($j=0;$j < $maxTitle; $j++){
$temp = '';
switch (Rand(0,6)){
case 0:
$temp = $faker->cityPrefix();
break;
case 1:
$temp = $faker->streetSuffix();
break;
case 2:
$temp = $faker->citySuffix();
break;
case 3:
$temp = $faker->word();
break;
case 4:
$temp = $faker->century();
break;
case 5:
$temp = $faker->lastName();
break;
case 6:
$temp = $faker->stateAbbr();
break;
}
$title .=' '. $temp;
}
$newProduct = Product::Create ([
'cid' => $cid,
'title' => ucwords($title),
'imgsrc' => $imgsrc,
'detail' => $detail,
'hadstock' => $hadstock,
'publisher' => ucwords($publisher),
'company' => ucwords($company),
//.........这里部分代码省略.........