Invoice path

This commit is contained in:
cuneytsenturk 2018-01-02 16:22:30 +03:00
parent 6429a699b2
commit ddd18c7ea6
7 changed files with 29 additions and 25 deletions

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers\Common;
use App\Http\Controllers\Controller;
use App\Models\Common\Media;
use Storage;
use File;
class Uploads extends Controller
{
@ -15,10 +16,12 @@ class Uploads extends Controller
* @param $file
* @return boolean|Response
*/
public function get($folder, $file)
public function get($id)
{
$media = Media::find($id);
// Get file path
if (!$path = $this->getPath($folder, $file)) {
if (!$path = $this->getPath($media)) {
return false;
}
@ -32,10 +35,12 @@ class Uploads extends Controller
* @param $file
* @return boolean|Response
*/
public function download($folder, $file)
public function download($id)
{
$media = Media::find($id);
// Get file path
if (!$path = $this->getPath($folder, $file)) {
if (!$path = $this->getPath($media)) {
return false;
}
@ -49,21 +54,23 @@ class Uploads extends Controller
* @param $file
* @return callable
*/
public function destroy($folder, $id)
public function destroy($id)
{
$media = Media::find($id);
// Get file path
/*if (!$path = $this->getPath($folder, $id)) {
$message = trans('messages.warning.deleted', ['name' => $file, 'text' => $file]);
if (!$path = $this->getPath($media)) {
$message = trans('messages.warning.deleted', ['name' => $media->basename, 'text' => $media->basename]);
flash($message)->warning();
return back();
}*/
}
$media->delete(); //will not delete files
File::delete($path);
return back();
}
@ -74,14 +81,13 @@ class Uploads extends Controller
* @param $file
* @return boolean|string
*/
protected function getPath($folder, $file)
protected function getPath($media)
{
// Add company id
if ($folder != 'users') {
$folder = session('company_id') . '/' . $folder;
}
$path = $media->basename;
$path = $folder . '/' . $file;
if (!empty($media->directory)) {
$path = $media->directory . '/' . $media->basename;
}
if (!Storage::exists($path)) {
return false;

View File

@ -416,7 +416,7 @@ class Invoices extends Controller
if ($request->file('attachment')) {
$media = $this->getMedia($request->file('attachment'), 'invoices');
$invoice->syncMedia($media, 'attachment');
$invoice->attachMedia($media, 'attachment');
}
// Delete previous invoice totals

View File

@ -56,7 +56,7 @@ class Items extends Controller
$item = Item::create($request->input());
// Upload picture
if ($media) {
if ($request->file('picture')) {
$media = $this->getMedia($request->file('picture'), 'items');
$item->attachMedia($media, 'picture');
@ -141,7 +141,7 @@ class Items extends Controller
$item->update($request->input());
// Upload picture
if ($media) {
if ($request->file('picture')) {
$media = $this->getMedia($request->file('picture'), 'items');
$item->syncMedia($media, 'picture');

View File

@ -11,4 +11,4 @@ class Media extends PMedia
protected $dates = ['deleted_at'];
}
}

View File

@ -36,10 +36,8 @@ trait Uploads
$company_id = session('company_id');
}
$path = config('filesystems.disks.uploads.root') . '/' . $company_id . '/' . $folder;
$path = $company_id . '/' . $folder;
config(['filesystems.disks.uploads.root' => $path]);
return MediaUploader::fromSource($file)->upload();
return MediaUploader::fromSource($file)->toDirectory($path)->upload();
}
}

View File

@ -189,7 +189,7 @@
{!! Form::open([
'id' => 'attachment-' . $invoice->attachment->id,
'method' => 'DELETE',
'url' => [url('uploads/invoices/' . $invoice->attachment->id)],
'url' => [url('uploads/' . $invoice->attachment->id)],
'style' => 'display:inline'
]) !!}
{{ Form::hidden('id', $invoice->id) }}

View File

@ -9,8 +9,8 @@
Route::group(['middleware' => 'language'], function () {
Route::group(['middleware' => 'auth'], function () {
Route::group(['prefix' => 'uploads'], function () {
Route::get('{folder}/{file}', 'Common\Uploads@get');
Route::get('{folder}/{file}/download', 'Common\Uploads@download');
Route::get('{id}', 'Common\Uploads@get');
Route::get('{id}/download', 'Common\Uploads@download');
Route::delete('{id}', 'Common\Uploads@destroy');
});