Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel store method

  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

PREVIOUS NEXT
Code Example
Php :: laravel log build 
Php :: sum of the array elements in php 
Php :: php convert string to boolean 
Php :: array collapse laravel 
Php :: php check valid time format 
Php :: convert laravel hash password online 
Php :: default value date symfony entity 
Php :: ACF Photo Gallery Output 
Php :: curl php 
Php :: php timezone 
Php :: laravel eloquent select one column in array 
Php :: What does PEAR stands for? 
Php :: php exponential operator 
Php :: how to get last id in database codeigniter 4 
Php :: php artisan tinker send email 
Php :: date format change in laravel blade 
Php :: laravel throw function 
Php :: get woocommerce product category link by id 
Php :: check if date between two dates laravel 
Php :: ternary expressions php 
Php :: check if phone number is valid php 
Php :: how to fix PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted 
Php :: spl_autoload_register 
Php :: php Convert String containing commas to array 
Php :: laravel validation greater than or equal to 
Php :: php continue 
Php :: add custom page to wordpress 
Php :: sum of multidimensional array in php 
Php :: laravel collection map 
Php :: test laravel scheduler 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =