本文整理汇总了PHP中App\Http\Requests\ArticleRequest::file方法的典型用法代码示例。如果您正苦于以下问题:PHP ArticleRequest::file方法的具体用法?PHP ArticleRequest::file怎么用?PHP ArticleRequest::file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Http\Requests\ArticleRequest
的用法示例。
在下文中一共展示了ArticleRequest::file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Function for storing a new blog article.
*
* @param $request
* @param ArticleRequest $request
* @return Redirect
*/
public function store(ArticleRequest $request)
{
if ($request->has('slug')) {
$request['slug'] = str_slug($request['slug'], "_");
} else {
$request['slug'] = str_slug($request['title'], "_");
}
$today = Carbon::today()->format('Y') . '/' . Carbon::today()->format('M') . '/' . Carbon::today()->format('d');
$uploadPath = base_path() . '/public/img/uploads/' . $today;
$article = Article::create($request->all());
// TODO: Refine into two seperate actions //
if (!empty($request['cover-image']) || !empty($request['cover-image'])) {
$SmallImageName = '/img/uploads/' . $today . '/' . $request['slug'] . '_sml' . '.' . $request->file('listing-image')->getClientOriginalExtension();
$coverImageName = '/img/uploads/' . $today . '/' . $request['slug'] . '_cover' . '.' . $request->file('cover-image')->getClientOriginalExtension();
$article['imgfull'] = $coverImageName;
$article['imgsml'] = $SmallImageName;
}
$article['page_code'] = str_random(16);
$article['author'] = Auth::user()->id;
$article['category'] = $request['category'];
// TODO:: Preform a check to see if this Category Exists //
$article['published'] = Carbon::parse($request['published']);
// TODO:: Add a time to publish field //
$article->save();
if (!empty($request['cover-image']) || !empty($request['cover-image'])) {
$request->file('listing-image')->move($uploadPath, $SmallImageName);
$request->file('cover-image')->move($uploadPath, $coverImageName);
}
return redirect('blog/' . $request->slug);
}
示例2: store
public function store(ArticleRequest $request)
{
if ($request->file('image')) {
$file = $request->file('image');
$name = "blogfacilito_" . time() . bcrypt(\Auth::user()) . "." . $file->getClientOriginalExtension();
$path = public_path() . "/images/articles/";
$file->move($path, $name);
}
$article = new Article($request->all());
$article->user_id = \Auth::user()->id;
$article->save();
$article->tags()->sync($request->tags);
$image = new Image();
$image->name = $name;
$image->article()->associate($article);
$image->save();
Flash::success("El articulo " . $article->title . " se ha creado satisfactoriamente!");
return redirect()->route('admin.articles.index');
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(ArticleRequest $request)
{
if ($request->file('image')) {
$file = $request->file('image');
$name = 'blogfacilito_' . time() . '.' . $file->getClientOriginalExtension();
$path = public_path() . '/images/articles/';
$file->move($path, $name);
}
$article = new Article($request->all());
$article->user_id = \Auth::user()->id;
$article->save();
$article->tags()->sync($request->tags);
$image = new Image();
$image->name = $name;
$image->article()->associate($article);
$image->save();
Flash::success('Se ha creado el articulo ' . $article->title . ' de forma exitosa!!');
return redirect()->route('admin.articles.index');
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(ArticleRequest $request)
{
// Manipulacion de imagenes
if ($request->file('image')) {
$file = $request->file('image');
$name = 'IN_' . time() . '.' . $file->getClientOriginalExtension();
$path = public_path() . '/images/articles/';
$file->move($path, $name);
}
$article = new Article($request->all());
$article->user_id = \Auth::user()->id;
$article->save();
$article->tags()->sync($request->tags);
$image = new Image();
$image->name = $name;
$image->article()->associate($article);
$image->save();
alert()->success('Enorabuena', 'El articulo ' . $article->title . ' ha sido creado con exito');
Flash::success('El articulo ' . $article->title . ' ha sido creado con exito¡');
return redirect()->route('admin.articles.index');
}
示例5: store
public function store(ArticleRequest $request)
{
if ($request->file('image')) {
//Manipulacion de imagenes
$file = $request->file('image');
$name = substr($file->getClientOriginalName(), 0, -4) . "_" . time() . '_image.' . $file->getClientOriginalExtension();
$path = base_path() . '/public/images/articles/';
$file->move($path, $name);
$image->name = $name;
}
$article = new Article($request->all());
$article->user_id = \Auth::user()->id;
$article->save();
$article->tags()->sync($request->tags);
$image = new Image();
$image->article_id = $article->id;
//$image->article()->associate();
$image->save();
Flash::success('Se ha agregado el articulo de forma satisfactoria.');
return redirect()->route('admin.articles.index');
}
示例6: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(ArticleRequest $request)
{
$article = Auth::user()->articles()->create($request->all());
$this->syncTags($article, $request->input('tag_list'));
if ($request->hasFile('cover')) {
$this->uploadFile($article, $request->file('cover'));
}
if ($request->has('twitter')) {
$this->tweet($article);
}
session()->flash('flash_message', 'Se ha publicado tu artículo');
return redirect('admin/articles');
}
示例7: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(ArticleRequest $request, Article $article)
{
$input = $request->all();
$article->update(['title' => $input['title'], 'body' => $input['body'], 'codice_prodotto' => $input['codice_prodotto'], 'disponibile' => $input['disponibile'], 'prezzo' => $input['prezzo'], 'categoria' => $input['categoria']]);
if ($request->file('immagine')) {
$imageName = $article->id . '.' . $request->file('immagine')->getClientOriginalExtension();
$request->file('immagine')->move(base_path() . '/public/images/catalog/', $imageName);
$article->update(['immagine' => $imageName]);
}
if ($request->ajax() || $request->wantsJson()) {
return new JsonResponse($article);
}
flash()->success('aggiornato con successo!');
return redirect('articles');
}
示例8: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(ArticleRequest $request, $id)
{
$data = [];
$article = Article::find($id);
$data['article_category_id'] = $request->get('article_category_id');
$data['title'] = $request->get('title');
$data['description'] = $request->get('description');
if ($request->file('image') != null) {
if (!$request->file('image')->isValid()) {
Session::flash('warning', "Gambar tidak berhasil disimpan!");
return redirect()->back()->withInput();
} else {
if ($article->image != null && file_exists('img/article/' . $article->image)) {
unlink('img/article/' . $article->image);
$data['image'] = time() . '.' . $request->file('image')->getClientOriginalExtension();
$request->file('image')->move('img/article', $data['image']);
}
}
}
$article->update($data);
Session::flash('success', "Artikel baru berhasil disunting!");
return redirect()->route('admin.article.index');
}
示例9: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id, ArticleRequest $request)
{
$article = Article::findOrFail($id);
$article->update($request->all());
// update image
if ($request->hasFile('image')) {
$image_filename = $request->file('image')->getClientOriginalName();
$image_name = date("Ymd-His-") . $image_filename;
$public_path = 'images/articles/';
$destination = base_path() . $public_path;
$request->file('image')->move($destination, $image_name);
$article->image = $public_path . $image_name;
$article->save();
}
$tagsId = $request->input('tag_list');
if (!empty($tagsId)) {
/* select */
$article->tags()->sync($tagsId);
} else {
/* Not select */
$article->tags()->detach();
}
session()->flash('flash_message', 'Edit completed');
return redirect('articles');
}
示例10: createArticle
/**
* Save a new article
* @param ArticleRequest $request
* @return mixed
*/
private function createArticle(ArticleRequest $request)
{
$article = Auth::user()->articles()->create($request->all());
$this->syncTags($article, $request->input('tag_list', []));
//获取收到“image”并存储
// $type = $request->file('image')->getClientOriginalExtension();
//$imageName = ($article->id) . '.' . $request->file('image')->getClientOriginalExtension();
$length = 6;
$randomString = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
if (mt_rand(0, 1) === 0) {
$zuoyou = 'right';
} else {
$zuoyou = 'left';
}
//判断是非mp4,Image不支持mp4,判断是否长图
if ($request->file('image')->getClientOriginalExtension() == 'mp4') {
copy($request->file('image'), base_path() . '/public/images/catalog/' . $randomString . '.mp4');
$article->type = '.mp4';
} else {
list($originalWidth, $originalHeight) = getimagesize($request->file('image'));
$ratio = $originalHeight / $originalWidth;
if ($ratio < '3.5') {
Image::make($request->file('image'))->resize(480, null, function ($constraint) {
$constraint->aspectRatio();
})->insert(base_path() . '/public/images/catalog/watermark.jpg', $zuoyou, 10)->encode('jpg')->save(base_path() . '/public/images/catalog/' . $randomString . '.jpg');
$article->type = '.jpg';
} else {
Image::make($request->file('image'))->resize(480, null, function ($constraint) {
$constraint->aspectRatio();
})->insert(base_path() . '/public/images/catalog/watermark.jpg', $zuoyou, 10)->encode('jpg')->save(base_path() . '/public/images/catalog/' . $randomString . '_long.jpg');
Image::make($request->file('image'))->resize(480, null, function ($constraint) {
$constraint->aspectRatio();
})->resizeCanvas(480, 285, 'top')->encode('jpg')->save(base_path() . '/public/images/catalog/' . $randomString . '.jpg');
$article->type = '_long.jpg';
}
}
//保存存储名字和extension
$article->photo = $randomString;
$article->save();
return $article;
}
示例11: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update(ArticleRequest $request, $id)
{
$article = Article::find($id);
//Check fileImage
if ($request->hasFile('image')) {
$image = $request->file('image');
$imagename = time() . '-' . $image->getClientOriginalName();
$image->move(public_path() . '/image', $imagename);
} else {
$imagename = $article->image;
}
//Status
if ($request->Input('status') == false) {
$status = 0;
} else {
$status = 1;
}
//data
$data = ['name' => $request->get('name'), 'summary' => $request->get('summary'), 'content' => $request->get('content'), 'image' => $imagename, 'status' => $status];
//update
//dd($data);
$article->update($data);
return redirect()->route('article.index');
}
示例12: update
/**
* update an existing article
*
* @param integer $id
* @param ArticleRequest $request
* @return Response
*/
public function update(Article $article, ArticleRequest $request)
{
$article->update($request->except('image'));
$article->slug = str_slug($request->title, '-');
if ($request->hasFile('image')) {
$file = $request->file('image');
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$image = sha1($filename . time()) . '.' . $extension;
$destinationPath = public_path('/uploads/images/');
$request->file('image')->move($destinationPath, $image);
$article->image = $image;
}
$article->update();
$this->syncTags($article, $request->input('tag_list'));
flash()->info('Artikel telah diperbarui!');
return redirect('/dashboard/articles');
}
示例13: update
public function update(Article $article, ArticleRequest $request)
{
//dd($request);
//$article = Article::findOrFail($id);
$article->update($request->all());
if ($request->file('fileField') != null) {
$article->fileField = $request->file('fileField')->getClientOriginalName();
Storage::put('Uploads/Articles/' . Auth::user()->username . '/' . $request->file('fileField')->getClientOriginalName(), file_get_contents($request->file('fileField')->getRealPath()));
}
$article->save();
//$article->tags()->detach();
$tagIDs = $request->input('tagList');
if (!is_null($tagIDs)) {
$article->tags()->sync($tagIDs);
}
//$article->tags()->attach($request->input('tagList'));
return redirect()->route('articles.show', ['articles' => $article->id]);
}
示例14: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(ArticleRequest $request, $id)
{
$article = Article::find($id);
if ($request->hasFile('image')) {
$path = base_path() . '/public/images';
$file = $request->input('image');
// $file->fit(120,90);
$fileName = $request->file('image')->getClientOriginalName();
$request->file('image')->move($path, $fileName);
$article->image = $fileName;
}
$article->update($request->all());
for ($i = 0; $i < sizeof($request->input('dealname')); $i++) {
$deal = $article->deals()->where('dayID', $i + 1)->first();
$deal->dealname = $request->input('dealname')[$i];
$deal->save();
}
// TO UPDATE CATEGORIES
$categoriesId = $request->input('categoryList');
$article->categories()->sync($categoriesId);
$daysId = $request->input('dayList');
$article->days()->sync($daysId);
return redirect('/');
}
示例15: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(ArticleRequest $request)
{
//Manipulación de imágenes
if ($request->file('image')) {
$file = $request->file('image');
//dd($file);
/*
Visualiza:
UploadedFile {#29 ▼
-test: false
-originalName: "a.png"
-mimeType: "image/png"
-size: 2381
-error: 0
*/
// Esto lo utilizamos por si se mandan 2 ficheros
// con el mismo nombre. Para evitar la colisión.
$name = 'blogfacilito_' . time() . '.' . $file->getClientOriginalExtension();
//dd($name);
/*
Visualiza:
"blogfacilito_1448476889.png"
(si actualizamos la página, obtenemos otro
nombre único)
"blogfacilito_1448476986.png"
*/
$path = public_path() . '/img/articles/';
//dd($path);
/*
Visualiza:
"C:\xampp\htdocs\CodigoFacilitoLaravel5\
Projects\blog\public/images/articles/"
*/
$file->move($path, $name);
}
$article = new Article($request->all());
// para obtener el usuario autentificado
$article->user_id = \Auth::user()->id;
//dd($article);
/*
Visualiza:
....
#attributes: array:3 [▼
"title" => "título"
"category_id" => "1"
"content" => "contenido"
]
....
*/
//dd(\Auth::user()->id);
/*
Visualiza: 1
*/
$article->save();
$article->tags()->sync($request->tags);
// sync lo que hace es rellenar la tabla
// pivote
$image = new Image();
$image->name = $name;
// Si varias personas están creando un artículo a la
// misma vez, podríamos tener un problema, ya que
// podríamos almacenar el id de un artículo incorrecto.
// Para evitarlo:
$image->article()->associate($article);
// associate() lo que va a hacer es pasar
// como parámetro el objeto $article, y va
// a tomar que es lo que lo asocia, en
// este caso lo que asocia a las imágenes
// y los artículos sería la llave foránea
// 'article_id'
$image->save();
Flash::success('Se ha creado el artículo ' . $article->title . ' de forma satisfactoria!');
return redirect()->route('admin.articles.index');
}