This repository was archived by the owner on Jul 15, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,49 @@ $result->getHeight(); // Get the height of the uploaded file
8282$result->getTimeUploaded(); // Get the time the file was uploaded
8383```
8484
85+ ** Attach Files/Media** to Laravel ** Eloquent Models** :
86+
87+ ``` php
88+ /**
89+ * How to attach a file to a Model by creating
90+ */
91+ $page = Page::create($this->request->input());
92+ $page->attachMedia($file); // Example of $file is $request->file('file');
93+
94+ /**
95+ * How to attach a file to a Model by retrieving
96+ */
97+ $page = Page::find(2);
98+ $page->attachMedia($file); // Example of $file is $request->file('file');
99+
100+ /**
101+ * How to retrieve files that were attached to a Model
102+ */
103+ $filesBelongingToSecondPage = Page::find(2)->fetchAllMedia();
104+
105+ /**
106+ * How to retrieve the first file that was attached to a Model
107+ */
108+ $fileBelongingToSecondPage = Page::find(2)->fetchFirstMedia();
109+
110+ /**
111+ * How to retrieve the last file that was attached to a Model
112+ */
113+ $fileBelongingToSecondPage = Page::find(2)->fetchLastMedia();
114+
115+ /**
116+ * How to replace/update files attached to a Model
117+ */
118+ $page = Page::find(2);
119+ $page->updateMedia($file); // Example of $file is $request->file('file');
120+
121+ /**
122+ * How to detach a file from a Model
123+ */
124+ $page = Page::find(2);
125+ $page->detachMedia($file) // Example of $file is $request->file('file');
126+ ```
127+
85128## Installation
86129
87130[ PHP] ( https://php.net ) 7.0+, and [ Composer] ( https://getcomposer.org ) are required.
You can’t perform that action at this time.
0 commit comments