/** * Store a newly created resource in storage. * * @return Response */ public function store(Requests\BlogCreateRequest $request) { $blog = new Blog(); $blog->title = Input::get('title'); $blog->content = Input::get('content'); // dd($blog); $blog->save(); $blog->tags()->attach([1, 3]); $blog->save(); return "Your blog created successfully! Your id is" . $blog->id; }
public function postAdd(Request $request) { if (!ACL::hasPermission('blog', 'add')) { return redirect(route('blog'))->withErrors(['Você não tem permissão para adicionar.']); } $this->validate($request, ['date' => 'required|max:10', 'title' => 'required|max:100', 'subtitle' => 'required|max:240', 'text' => 'required', 'tags' => 'required', 'image' => 'required|image|mimes:jpeg,gif,png'], ['date.required' => 'Informe a data', 'date.max' => 'A data não pode passar de :max caracteres', 'title.required' => 'Informe o título', 'title.max' => 'O título não pode passar de :max caracteres', 'subtitle.required' => 'Informe o sub-título', 'subtitle.max' => 'O sub-título não pode passar de :max caracteres', 'text.required' => 'Informe o texto', 'tags.required' => 'Informe as tags', 'image.required' => 'Envie a imagem', 'image.image' => 'Envie um formato de imagem válida', 'image.mimes' => 'Formatos suportados: .jpg, .gif e .png']); $blog = new Blog(); $blog->date = Carbon::createFromFormat('d/m/Y', $request->date)->format('Y-m-d'); $blog->title = $request->title; $blog->subtitle = $request->subtitle; $blog->text = $request->text; $blog->autorSource = $request->autorSource; $blog->tags = $request->tags; $blog->slug = str_slug($request->title, '-'); //IMAGE $extension = $request->image->getClientOriginalExtension(); $nameImage = Carbon::now()->format('YmdHis') . "." . $extension; $image = Image::make($request->file('image')); if ($request->imageCropAreaW > 0 or $request->imageCropAreaH > 0 or $request->imagePositionX or $request->imagePositionY) { $image->crop($request->imageCropAreaW, $request->imageCropAreaH, $request->imagePositionX, $request->imagePositionY); } $image->resize($this->imageWidth, $this->imageHeight)->save($this->folder . $nameImage); $blog->image = $nameImage; $blog->save(); $success = "Matéria adicionada com sucesso."; return redirect(route('blog'))->with(compact('success')); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(BlogFormRequest $request) { $user = Auth::user(); $slug = uniqid(); $blog = new Blog(['title' => $request->get('title'), 'content' => $request->get('content'), 'slug' => $slug, 'user_id' => $user->id]); $blog->save(); return redirect('/blogs')->with('status', 'You have successfully created a blog!'); }
public function setBlog($data) { $blog = new Blog(); $blog->title = $data['title']; $blog->post = strip_tags($data['post']); $blog->user_id = Auth::user()->id; $blog->save(); return true; }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $this->validate($request, ['title' => 'required|unique:blogs|max:255', 'body' => 'required']); $blog = new Blog(); $blog->title = $request->input("title"); $blog->body = $request->input("body"); $blog->save(); return redirect()->route('blogs.index')->with('message', 'Item created successfully.'); }
public function store() { $b = new Blog(); $b->title = $_POST['title']; $b->date = $_POST['date']; $b->content = $_POST['content']; $b->save(); Functions::redirect('/'); }
public function update(BlogEditRequest $request, Blog $blog) { $blog->name = $request->get("name"); $blog->slug = $request->get("slug"); $blog->content = $request->get("content"); $blog->is_published = $request->get("is_published"); $blog->save(); return redirect()->route("backend.blog.edit", $blog->slug); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // $this->validate($request, ['title' => 'required|min:5', 'subject' => 'required|min:20']); $blog = new Blog(); $blog->title = $request->title; $blog->subject = $request->subject; $blog->slug = str_slug($request->title, '-'); $blog->save(); return redirect('crud')->with('pesan', 'blog sudah di tambah'); }
public function store(Request $request) { $user = Sentinel::getUser()->id; $rules = ['title' => 'required|min:5|max:150|regex:(^[a-zA-Z0-9]+$)|unique:blogs', 'content' => 'required|min:10']; $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { return back()->withInput()->withErrors($validator); } else { # Create Blog $blog = new Blog(); $blog->title = $request->title; $blog->content = $request->content; $blog->user_id = $user; if ($blog->save()) { $tags = $request->tags; foreach ($tags as $tag) { if (is_numeric($tag)) { $tagableSave = new Taggable(); $tagableSave->taggable_id = $blog->id; $tagableSave->tag_id = $tag; $tagableSave->taggable_type = 'App\\Blog'; $tagableSave->user_id = $user; $tagableSave->save(); } else { if (strlen($tag) >= 3) { $tagExist = Tag::where('text', $tag)->count(); if ($tagExist == 0) { $tagSave = new Tag(); $tagSave->text = $tag; $tagSave->save(); $tagableSave = new Taggable(); $tagableSave->taggable_id = $blog->id; $tagableSave->tag_id = $tagSave->id; $tagableSave->taggable_type = 'App\\Blog'; $tagableSave->user_id = $user; $tagableSave->save(); } } } } # Redirect on Success return redirect()->route('user.blog.index')->with('success', trans('validation.blog_success')); } } return back()->withInput()->with('error', 'مشکل در اتصال به سرور. لطفا مجددا تلاش کنید.'); }
public function update(BlogCreateRequest $request, Blog $blog) { $blog->name = $request->get("name"); $blog->content = $request->get("content"); if ($request->hasFile("image")) { if (file_exists(public_path() . "/" . $blog->image)) { unlink(public_path() . "/" . $blog->image); } do { $imageName = str_random(5) . "-" . $request->file("image")->getClientOriginalName(); } while (file_exists(public_path() . "/upload/blogs/" . $imageName)); $request->file("image")->move(public_path() . "/upload/blogs/", $imageName); $blog->image = "upload/blogs/" . $imageName; } $blog->save(); return redirect()->route("admin.blog.edit", $blog->id)->with("success", trans("realestateadmin::blog.edited")); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $blog = new Blog(); $blog->title = Request::input('title'); $blog->description = Request::input('description'); $blog->category_id = Request::input('category_id'); $blog->author = Request::input('author'); $blog->public_date = Request::input('public_date'); $blog->save(); if (Request::hasFile('image')) { Request::file('image')->move(public_path('blog/images'), $blog->id . '.jpg'); } foreach (Request::input('tags') as $tagId) { $blogTag = new BlogTag(); $blogTag->blog_id = $blog->id; $blogTag->tag_id = $tagId; $blogTag->save(); } return redirect()->route('blog_index'); }
public function index($id) { //$articles=DB::table('blog_articles')->where('blog_id','=',$id)->paginate(15); if (Auth::user()->tag == 'teacher') { $user = User::find($id); $blog = $user->blog; if (empty($blog)) { # code... $blog = new Blog(); $blog->name = $user->name; $blog->user_id = $user->id; $blog->save(); } $articles = $blog->articles()->get(); $user = User::find($id); $data = array('articles' => $articles, 'user' => $user, 'blog' => $blog); //return $data; return view('blog.admin.index')->with('data', $data); } else { return '该博客暂时不对实验室外部人员开放'; } }
public function update(Request $request, Blog $blog) { $insert = $blog->fill($request->input())->save(); $image = \Input::get('image'); if ($image != '') { $imagename = 'blog-' . rand(11111, 99999) . '-gudperna.png'; $image = str_replace(' ', '+', $image); list($type, $image) = explode(';', $image); list(, $image) = explode(',', $image); $image = base64_decode($image); file_put_contents('upload/img/' . $imagename, $image); $blog->image = $imagename; $blog->save(); } if ($insert) { return 0; } else { return 1; } }
/** * Store a newly created resource in storage. * * @return Response */ public function postCreate(BlogRequest $request) { $blog = new Blog($request->except('image', 'tags')); $picture = ""; if ($request->hasFile('image')) { $file = $request->file('image'); $filename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension() ?: 'png'; $folderName = '/uploads/blog/'; $picture = str_random(10) . '.' . $extension; } $blog->user_id = Sentinel::getUser()->id; $blog->image = $picture; $blog->save(); if ($request->hasFile('image')) { $destinationPath = public_path() . $folderName; $request->file('image')->move($destinationPath, $picture); } $blog->tag($request['tags']); return redirect('admin/blog'); }
Route::get('/', 'PagesController@home'); Route::get('/about/{name}', 'PagesController@about'); Route::get('/contact', 'PagesController@contact'); Route::get('auth/login', 'Auth\\AuthController@getLogin'); Route::post('auth/login', 'Auth\\AuthController@postLogin'); Route::get('auth/logout', 'Auth\\AuthController@getLogout'); // Registration routes... Route::get('auth/register', 'Auth\\AuthController@getRegister'); Route::post('auth/register', 'Auth\\AuthController@postRegister'); use App\User; use App\Blog; Route::get('/user', function () { dd(User::all()); }); Route::get('/blog/create', function () { $blog = new Blog(); $blog->name = "First Blog"; $blog->description = "First Blog"; $blog->save(); }); Route::get('/blog', function () { return Blog::all(); }); Route::get('/blog/{id}', function ($id) { $blog = Blog::find($id); return $blog; }); Route::get('/blog/t/{tit}', function ($tit) { $blog = Blog::where('name', "=", $tit)->get(); return $blog; });
public function posteditblog(Request $request) { $model_blog = new Blog(); $model_blog->title = $request->input('title'); $model_blog->content = $request->input('content'); $model_blog->save(); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(BlogRequest $request) { $blog = new Blog($request->except('image', 'tags')); if ($request->hasFile('image')) { $file = $request->file('image'); $filename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension() ?: 'png'; $folderName = '/uploads/blog/'; $picture = str_random(10) . '.' . $extension; $blog->image = $picture; } $blog->user_id = Sentinel::getUser()->id; $blog->save(); if ($request->hasFile('image')) { $destinationPath = public_path() . $folderName; $request->file('image')->move($destinationPath, $picture); } $blog->tag($request->tags); if ($blog->id) { return redirect('admin/blog')->with('success', trans('blog/message.success.create')); } else { return Redirect::route('admin/blog')->withInput()->with('error', trans('blog/message.error.create')); } }
public function postSimpan(Request $request) { $this->validate($request, ['judul' => 'required|unique:site_blog|min:3', 'konten' => 'required', 'kategori' => 'required']); $slug = str_slug($request->judul, "-"); if ($request->hasFile('gambar')) { if ($request->file('gambar')->isValid()) { $ext = $request->file('gambar')->getClientOriginalExtension(); $nm_gambar = str_limit($slug, 30); $nm_gambar = rand(11111, 99999) . "-" . $nm_gambar . "." . $ext; $request->file('gambar')->move(base_path() . "/resources/assets/img/blog/", $nm_gambar); } else { return redirect()->route('blog_tambah'); } } else { $nm_gambar = ""; } // Simpan blog $Blog = new Blog(); $Blog->judul = $request->judul; $Blog->slug = $slug; $Blog->konten = $request->konten; $Blog->gambar = $nm_gambar; $Blog->tag = $request->tags; $Blog->draft = $request->draft; $Blog->id_user = $this->User->id; $Blog->save(); $id = $Blog->id; // Simpan kategori $kategori = explode(",", $request->kategori); foreach ($kategori as $val) { if (empty($val)) { continue; } $BlogKat = new BlogKategori(); $BlogKat->id_kategori = $val; $BlogKat->id_blog = $id; $BlogKat->save(); } $request->session()->flash('success', 'Berhasil menyimpan data'); return redirect()->route('blog_edit', [$id]); }