redroseamit's avatar

how to create upload pdf file in controller using store method of resource controller.

public function store(Request $request)
    {
       
        $this->validate($request, [
            
            'name' => 'required',
            'details' => 'required',
            'image' => 'required|image|mimes:jpeg,png,jpg,pdf,doc,docx|max:2048',
            
            
        ]);

   /*   
       how can i upload a pdf file  and create do.wnload link in view page

*/ 

   
  
        $notification = array(
        'message' => 'Your Estimate document submitted successfully', 
        'alert-type' => 'success'
        );

        return view ('users.index')->with($notification);

    
    
    }
0 likes
10 replies
redroseamit's avatar

sir by using this code i am able to upload image only not pdf why ?

public function store(Request $request)
    {
       
        $this->validate($request, [
            
            'name' => 'required',
            'details' => 'required',
            'image' => 'required|image|mimes:jpeg,png,jpg,pdf|max:2048',
            
            
        ]);

      if ($files = $request->file('image')) {
        $files->move('storage/app/image/', $image = date('YmdHis').'.'.$files->getClientOriginalExtension());
    }

    Package::create($request->except('image') + [
        'image' => $image ?? null
    ]);   



MichalOravec's avatar

Because pdf is not an image.

Remove image from validation rules.

'image' => 'required|mimes:jpeg,png,jpg,pdf|max:2048',
3 likes
redroseamit's avatar

thank you so much sir ...love you from heart ..you are the one save me always ...i am spending lot of time behind the error i hope one day i will became expert like you ,

jlrdw's avatar
jlrdw
Best Answer
Level 75

@redroseamit so are you skipping validation for pdf.

Granted it wasn't an image, but you should still (or can) validate:

$rules  = [
    "file" => "required|mimetypes:application/pdf|max:10000"
]

Or something like:

$request->validate([
    'file.*' => 'required|file|max:5000|mimes:pdf,docx,doc',
]);

But glad you got it all solved.

3 likes
redroseamit's avatar

thats what i want to do .... is laravel automatilcally detects its image or file i thought if i will write image it will work as a file .....well thank you so much sir for your help..

redroseamit's avatar

sorry sir i thought ,it will guess it as a file not a image so i assign a name image to it ... sir i want to implement web socket in my project i don't want to use any channel for it like pusher or something else... can i try to do that ?need your some help also there there is no good package available for implement real time chat service.

Please or to participate in this conversation.