本文整理汇总了PHP中app\models\Article::fill方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::fill方法的具体用法?PHP Article::fill怎么用?PHP Article::fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Article
的用法示例。
在下文中一共展示了Article::fill方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionNew
public function actionNew()
{
if ($this->isPost()) {
$article = new Article();
try {
$article->fill($_POST);
$article->save();
$this->redirect('/admin');
} catch (MultiException $error) {
$this->view->article = $article;
$this->view->error = $error;
}
} else {
$this->view->error = false;
}
$this->view->display(__DIR__ . '/../../templates/new.php');
}
示例2: store
/**
* store a resource
* @param Request $request http request
* @param mixed $id id of the resource for updating
* @return jsend jsend with newly stored source
*/
function store(Request $request, $id = null)
{
////////////////
// Load Data //
////////////////
if ($id) {
$data = Model::find($id);
if (!$data) {
return app()->abort(404);
}
} else {
$data = new Model();
}
///////////////////////////////////
// Assign posted data to Data //
///////////////////////////////////
$data->fill($request->input());
///////////////////////////////////////////////////////////////////
// Validate data //
///////////////////////////////////////////////////////////////////
# Validate User
if ($request->input('user_id')) {
if (!is_scalar($request->input('user_id'))) {
return response()->json(JSend::fail(['user' => ['Invalid User']])->asArray());
} else {
$user = User::find($request->input('user_id'));
if (!$user) {
return response()->json(JSend::fail(['user' => ['Invalid User']])->asArray());
}
$data->user_id = $request->input('user_id');
}
}
///////////////////////////
// Embeds Other Document //
///////////////////////////
///////////////////////
// EMBED IMAGES //
///////////////////////
foreach ($this->request->input('images') as $x) {
$images[] = new Image($x);
}
if (!$data->syncImages($images)) {
return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback'));
}
///////////////////////
// EMBED TAGS //
///////////////////////
foreach ($this->request->input('tags') as $x) {
$tags[] = new Tag($x);
}
if (!$data->syncTags($tags)) {
return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback'));
}
///////////
// Store //
///////////
if ($data->save()) {
return response()->json(JSend::success(['data' => $data])->asArray());
} else {
return response()->json(JSend::fail($data->getErrors())->asArray());
}
}
示例3: storeArticle
/**
* Stores an article
* @return Response
*/
public function storeArticle()
{
$data = Input::all();
$article = new Article();
if ($article->validate($data)) {
$file = Input::file('featured');
if ($file != null && $file->isValid()) {
$data['featured_img'] = 'articles/' . $article->id . '/' . time() . $file->getClientOriginalName();
$file->move(public_path('files/articles/' . $article->id), $data['featured_img']);
}
$user = Auth::user();
$article->fill($data);
$article->user_id = $user->id;
$article->save();
Alert::success('Article created ' . ($article->published ? 'and published' : '') . ' successfully. You may go to menus to link this article to a menu', 'Success');
return Redirect::to('admin/articles')->withSuccess('<strong>Article created successfully.</strong>');
}
Input::flash();
return View::make('admin.articles.create')->withErrors($article->getValidator());
}