mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-05 05:24:35 -04:00
Catch Model Not Found and return JSON
This commit is contained in:
parent
fd085e7e9c
commit
ef08afc240
@ -5,6 +5,7 @@ namespace App\Exceptions;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
use Illuminate\Auth\AuthenticationException;
|
use Illuminate\Auth\AuthenticationException;
|
||||||
|
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;
|
||||||
|
|
||||||
class Handler extends ExceptionHandler
|
class Handler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
@ -36,6 +37,9 @@ class Handler extends ExceptionHandler
|
|||||||
public function report(Exception $exception)
|
public function report(Exception $exception)
|
||||||
{
|
{
|
||||||
parent::report($exception);
|
parent::report($exception);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,9 +49,17 @@ class Handler extends ExceptionHandler
|
|||||||
* @param \Exception $exception
|
* @param \Exception $exception
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function render($request, Exception $exception)
|
public function render($request, Exception $exception)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if ($exception instanceof ModelNotFoundException)
|
||||||
|
{
|
||||||
|
return response()->json(['error'=>'Record not found'],400);
|
||||||
|
}
|
||||||
|
|
||||||
return parent::render($request, $exception);
|
return parent::render($request, $exception);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function unauthenticated($request, AuthenticationException $exception)
|
protected function unauthenticated($request, AuthenticationException $exception)
|
||||||
|
@ -76,13 +76,15 @@ class ClientController extends BaseController
|
|||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'client' => $client,
|
'client' => $client,
|
||||||
|
'hashed_id' => $this->encodePrimarykey($client->id),
|
||||||
'company' => $client->company(),
|
'company' => $client->company(),
|
||||||
'meta' => collect([
|
'sizes' => Size::all(),
|
||||||
'google_maps_api_key' => config('ninja.google_maps_api_key')
|
|
||||||
])
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return redirect()->route('clients.edit', ['id' => $this->encodePrimarykey($client->id)]);
|
return response()->json($data);
|
||||||
|
|
||||||
|
// return redirect()->route('api.clients.edit', ['id' => $this->encodePrimarykey($client->id)]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class InvoiceController extends BaseController
|
class InvoiceController extends BaseController
|
||||||
@ -23,23 +24,22 @@ class InvoiceController extends BaseController
|
|||||||
* ClientController constructor.
|
* ClientController constructor.
|
||||||
* @param ClientRepository $clientRepo
|
* @param ClientRepository $clientRepo
|
||||||
*/
|
*/
|
||||||
public function __construct(ClientRepository $clientRepo)
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->clientRepo = $clientRepo;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public function index(ClientFilters $filters)
|
public function index()
|
||||||
{
|
{
|
||||||
|
|
||||||
$clients = Client::filter($filters);
|
// $clients = Client::filter($filters);
|
||||||
|
|
||||||
return $this->listResponse($clients);
|
// return $this->listResponse($clients);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
84
app/Http/Controllers/QuoteController.php
Normal file
84
app/Http/Controllers/QuoteController.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class QuoteController extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for creating a new resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show($id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for editing the specified resource.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function edit($id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function update(Request $request, $id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
84
app/Http/Controllers/RecurringInvoiceController.php
Normal file
84
app/Http/Controllers/RecurringInvoiceController.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class RecurringInvoiceController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for creating a new resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show($id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for editing the specified resource.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function edit($id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function update(Request $request, $id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
@ -29,7 +29,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
parent::boot();
|
parent::boot();
|
||||||
|
|
||||||
Route::bind('client', function ($value) {
|
Route::bind('client', function ($value) {
|
||||||
$client = \App\Models\Client::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404);
|
$client = \App\Models\Client::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
||||||
$client->with('contacts', 'primary_contact','country');
|
$client->with('contacts', 'primary_contact','country');
|
||||||
return $client;
|
return $client;
|
||||||
});
|
});
|
||||||
@ -119,7 +119,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
protected function mapApiRoutes()
|
protected function mapApiRoutes()
|
||||||
{
|
{
|
||||||
Route::prefix('api/v1')
|
Route::prefix('')
|
||||||
->middleware('api')
|
->middleware('api')
|
||||||
->namespace($this->namespace)
|
->namespace($this->namespace)
|
||||||
->group(base_path('routes/api.php'));
|
->group(base_path('routes/api.php'));
|
||||||
|
@ -25,7 +25,7 @@ Route::group(['middleware' => ['api_secret_check']], function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Route::group(['middleware' => ['db','api_secret_check','token_auth']], function () {
|
Route::group(['middleware' => ['db','api_secret_check','token_auth'], 'prefix' =>'api/v1', 'as' => 'api.'], function () {
|
||||||
|
|
||||||
Route::resource('clients', 'ClientController'); // name = (clients. index / create / show / update / destroy / edit
|
Route::resource('clients', 'ClientController'); // name = (clients. index / create / show / update / destroy / edit
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ Route::group(['middleware' => ['db','api_secret_check','token_auth']], function
|
|||||||
Route::post('recurring_invoices/bulk', 'RecurringInvoiceController@bulk')->name('recurring_invoices.bulk');
|
Route::post('recurring_invoices/bulk', 'RecurringInvoiceController@bulk')->name('recurring_invoices.bulk');
|
||||||
|
|
||||||
Route::resource('client_statement', 'ClientStatementController@statement'); // name = (client_statement. index / create / show / update / destroy / edit
|
Route::resource('client_statement', 'ClientStatementController@statement'); // name = (client_statement. index / create / show / update / destroy / edit
|
||||||
|
/*
|
||||||
Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit
|
Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit
|
||||||
|
|
||||||
Route::post('tasks/bulk', 'TaskController@bulk')->name('tasks.bulk');
|
Route::post('tasks/bulk', 'TaskController@bulk')->name('tasks.bulk');
|
||||||
@ -64,7 +64,7 @@ Route::group(['middleware' => ['db','api_secret_check','token_auth']], function
|
|||||||
Route::resource('user', 'UserProfileController'); // name = (clients. index / create / show / update / destroy / edit
|
Route::resource('user', 'UserProfileController'); // name = (clients. index / create / show / update / destroy / edit
|
||||||
|
|
||||||
Route::get('settings', 'SettingsController@index')->name('user.settings');
|
Route::get('settings', 'SettingsController@index')->name('user.settings');
|
||||||
|
*/
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ Route::group(['middleware' => ['auth:user', 'db']], function () {
|
|||||||
Route::post('clients/bulk', 'ClientController@bulk')->name('clients.bulk');
|
Route::post('clients/bulk', 'ClientController@bulk')->name('clients.bulk');
|
||||||
|
|
||||||
Route::resource('client_statement', 'ClientStatementController@statement'); // name = (client_statement. index / create / show / update / destroy / edit
|
Route::resource('client_statement', 'ClientStatementController@statement'); // name = (client_statement. index / create / show / update / destroy / edit
|
||||||
|
/*
|
||||||
Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit
|
Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit
|
||||||
|
|
||||||
Route::post('tasks/bulk', 'TaskController@bulk')->name('tasks.bulk');
|
Route::post('tasks/bulk', 'TaskController@bulk')->name('tasks.bulk');
|
||||||
@ -80,7 +80,7 @@ Route::group(['middleware' => ['auth:user', 'db']], function () {
|
|||||||
Route::resource('user', 'UserProfileController'); // name = (clients. index / create / show / update / destroy / edit
|
Route::resource('user', 'UserProfileController'); // name = (clients. index / create / show / update / destroy / edit
|
||||||
|
|
||||||
Route::get('settings', 'SettingsController@index')->name('user.settings');
|
Route::get('settings', 'SettingsController@index')->name('user.settings');
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user