Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel save photo in both local and database

  public function store(StorePostRequest $request)
    {

		$request->validate([
            //unique:table,column
            "title" => "required|unique:posts,title|min:5",
            "description" => "required|min:15",
            "cover" => "required|file|mimes:jpeg,png|max:5000"
        ]);
        
//photo Save in local
        $newName = "cover_".uniqid()."_".$request->file('cover')->extension();
        $request->file('cover')->storeAs("public/cover",$newName);

//store in database
        $post = new Post();
        $post->title = $request->title;
        $post->slug = Str::slug($request->title);
        $post->description = $request->description;
        $post->excerpt = Str::words($request->description,50);
        $post->cover = $newName;
        $post->user_id = Auth::id();
        $post->save();


        return redirect()->route("index")->with('status','Post Created');

        return $request;
    }
Comment

display image from database in laravel

<img src="{{ asset('img/' . $post->image) }}" />
Comment

PREVIOUS NEXT
Code Example
Php :: php upload file 
Php :: password validation rules laravel 
Php :: laravel get single column value 
Php :: php copy image from remote to local server 
Php :: cloudinary laravel 
Php :: laravel online hash password generator 
Php :: rule In in laravel 
Php :: get first name user 
Php :: laravel sluggable 
Php :: timezone php 
Php :: wp get tagline 
Php :: php redirect seconds 
Php :: php implode array 
Php :: how to get last id in database 
Php :: laravel chunk select 
Php :: php do while loop 
Php :: laravel 8 try catch 
Php :: php to list files 
Php :: How to get the current taxonomy term ID (not the slug) in WordPress? 
Php :: php header redirect with parameters 
Php :: php compare two arrays of objects 
Php :: php conditionally remove element from array 
Php :: wordpress custom php use wp query 
Php :: Convert String containing commas to array 
Php :: php round to the nearest 10 
Php :: update php version in laravel 
Php :: multiple routes same controller laravel 
Php :: how to get correct file or content mime type using/in php 
Php :: laravel eloquent select case when 
Php :: php nginx file not found 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =