jeudi 26 octobre 2017

how to insert taskId in to the file table in Laravel

in My Laravel application I have file attachment form,

files/form.blade.php

<form class="form-vertical" role="form"
                                    enctype="multipart/form-data"
                                    method="post"
                                    action="">
            <div class="form-group">
                <input type="file" name="file_name" class="form-control" id="file_name">
                @if ($errors->has('file_name'))
                    <span class="help-block"></span>
                @endif
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-info">Add Files</button>
            </div>

FilesController

public function uploadAttachments(Request $request, $id)
            {
                 $this->validate($request, [
                    'file_name'     => 'required|mimes:jpeg,bmp,png,pdf|between:1,7000',
                ]);

                $filename     = $request->file('file_name')->getRealPath();

                Cloudder::upload($filename, null);
                list($width, $height) = getimagesize($filename);

                $fileUrl = Cloudder::show(Cloudder::getPublicId(), ["width" => $width, "height" => $height]);
                $this->saveUploads($request, $fileUrl, $id);

                return redirect()->back()->with('info', 'Your Attachment has been uploaded Successfully');
            }

            private function saveUploads(Request $request, $fileUrl, $id,)
            {
                $file = new File;
                $file->file_name  = $request->file('file_name')->getClientOriginalName();
                $file->file_url   = $fileUrl;
                $file->project_id = $id;

                $file->save();
            }

routes

Route::post('projects/{projects}/files', [
     'uses' => 'FilesController@uploadAttachments',
     'as'   => 'projects.files',
     'middleware' => ['auth']
]);

in My application in each project have many tasks. in one task may have many files. so now I need enter current taskId to the file table. how can I do it?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2i7fHEJ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire