Skip to content

Commit

Permalink
Update to laravel 8, use livewire, dump datatables.
Browse files Browse the repository at this point in the history
  • Loading branch information
zack6849 committed Mar 6, 2021
1 parent 23eb3ec commit 39fac07
Show file tree
Hide file tree
Showing 39 changed files with 4,700 additions and 2,007 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/UploadScan.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ public function handle()
$file->save();
$this->info("- Added $file_path to the database");
}
return true;
return 1;
}
}
19 changes: 5 additions & 14 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
Expand All @@ -29,10 +29,11 @@ class Handler extends ExceptionHandler
/**
* Report or log an exception.
*
* @param \Exception $exception
* @param Throwable $exception
* @return void
* @throws Throwable
*/
public function report(Exception $exception)
public function report(Throwable $exception)
{
parent::report($exception);
}
Expand All @@ -44,18 +45,8 @@ public function report(Exception $exception)
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
public function render($request, Throwable $exception)
{
return parent::render($request, $exception);
}

//todo: remove this and upgrade to laravel 6 soon, datatables is holding out for laravel6 official release.
protected function whoopsHandler()
{
try {
return app(\Whoops\Handler\HandlerInterface::class);
} catch (\Illuminate\Contracts\Container\BindingResolutionException $e) {
return (new \Illuminate\Foundation\Exceptions\WhoopsHandler)->forDebug();
}
}
}
17 changes: 16 additions & 1 deletion app/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
Expand All @@ -25,8 +26,22 @@
* @method static \Illuminate\Database\Eloquent\Builder|\App\File whereOriginalFilename($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\File whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\File whereUserId($value)
* @property string $filename
* @property int $size
* @property-read \App\User $user
* @method static \Illuminate\Database\Eloquent\Builder|File search($search)
* @method static \Illuminate\Database\Eloquent\Builder|File whereFilename($value)
* @method static \Illuminate\Database\Eloquent\Builder|File whereSize($value)
*/
class File extends Model
{
//
public function user(){
return $this->belongsTo(User::class);
}

public function scopeSearch(Builder $builder, $search){
return $builder->where('filename', 'like', "%$search%")
->orWhere('original_filename', 'like', "%$search%")
->orWhere('mime', 'like', "%$search%");
}
}
14 changes: 1 addition & 13 deletions app/Http/Controllers/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,7 @@ class FileController extends Controller
*/
public function index()
{
/** @var User $user */
$user = auth()->user();
return view('files.index', ['files' => $user->files()->orderBy('created_at', 'desc')->paginate(15)]);
}

public function ajaxIndex(){
/** @var User $user */
$user = auth()->user();
return DataTables::eloquent($user->files()->orderBy('created_at', 'desc'))->addColumn('delete_url', function(File $file){
return URL::temporarySignedRoute('file.request.delete', now()->addMinutes(10), ['file_id' => $file->id]);
})->addColumn('view_url', function($file){
return route('file.show', ['file_id' => $file->filename]);
})->toJson();
return view('files.index');
}

/**
Expand Down
41 changes: 41 additions & 0 deletions app/Http/Livewire/Files/Table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Http\Livewire\Files;

use App\File;
use Livewire\Component;
use Livewire\WithPagination;

class Table extends Component
{

use WithPagination;

public $perPage = 50;
public $sortField = 'created_at';
public $sortAsc = false;
public $search = '';
public $includeDeleted = false;

public function sortBy($field)
{
if ($this->sortField === $field) {
$this->sortAsc = !$this->sortAsc;
} else {
$this->sortAsc = true;
}
$this->sortField = $field;
}

public function clear()
{
$this->search = '';
}

public function render()
{
$user = auth()->user();
$files = $user->files()->search($this->search)->orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')->paginate($this->perPage);
return view('livewire.files.table', compact('files'));
}
}
4 changes: 4 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
* @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePassword($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereUpdatedAt($value)
* @property string|null $api_token
* @property-read int|null $files_count
* @property-read int|null $notifications_count
* @method static \Illuminate\Database\Eloquent\Builder|User whereApiToken($value)
*/
class User extends Authenticatable
{
Expand Down
38 changes: 18 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
"require": {
"php": "^7.1.3",
"doctrine/dbal": "~2.3",
"facade/ignition": "^1.0",
"fideloper/proxy": "^4.0",
"facade/ignition": "^2.3.6",
"fideloper/proxy": "^4.2",
"guzzlehttp/guzzle": "^7.0.1",
"intervention/image": "^2.5",
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0",
"twilio/sdk": "^6.4",
"yajra/laravel-datatables-oracle": "~9.5.0"
"laravel/framework": "^8.0",
"laravel/tinker": "^2.0",
"laravel/ui": "^3.0",
"livewire/livewire": "^2.4",
"twilio/sdk": "^6.4"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.2",
"barryvdh/laravel-ide-helper": "^2.6",
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^7.5"
"barryvdh/laravel-debugbar": "^3.3",
"barryvdh/laravel-ide-helper": "^2.7",
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.0"
},
"config": {
"optimize-autoloader": true,
Expand All @@ -40,12 +40,10 @@
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
Expand Down
Loading

0 comments on commit 39fac07

Please sign in to comment.