mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 07:24:35 -04:00
Use factories to create default models
This commit is contained in:
parent
b5687c91af
commit
ce16c4d4c0
19
app/Factory/ClientContactFactory.php
Normal file
19
app/Factory/ClientContactFactory.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Factory;
|
||||||
|
|
||||||
|
use App\Models\ClientContact;
|
||||||
|
|
||||||
|
class ClientContactFactory
|
||||||
|
{
|
||||||
|
public static function create(int $company_id, int $user_id) :ClientContact
|
||||||
|
{
|
||||||
|
$client_contact = new ClientContact;
|
||||||
|
$client_contact->first_name = "";
|
||||||
|
$client_contact->user_id = $user_id;
|
||||||
|
$client_contact->company_id = $company_id;
|
||||||
|
$client_contact->id = 0;
|
||||||
|
|
||||||
|
return $client_contact;
|
||||||
|
}
|
||||||
|
}
|
27
app/Factory/ClientFactory.php
Normal file
27
app/Factory/ClientFactory.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Factory;
|
||||||
|
|
||||||
|
use App\Models\Client;
|
||||||
|
|
||||||
|
class ClientFactory
|
||||||
|
{
|
||||||
|
public static function create(int $company_id, int $user_id) :Client
|
||||||
|
{
|
||||||
|
$client = new Client;
|
||||||
|
$client->company_id = $company_id;
|
||||||
|
$client->user_id = $user_id;
|
||||||
|
$client->name = '';
|
||||||
|
$client->website = '';
|
||||||
|
$client->private_notes = '';
|
||||||
|
$client->balance = 0;
|
||||||
|
$client->paid_to_date = 0;
|
||||||
|
$client->country_id = 4;
|
||||||
|
$client->is_deleted = 0;
|
||||||
|
|
||||||
|
$client_contact = ClientContactFactory::create($company_id, $user_id);
|
||||||
|
$client->contacts->add($client_contact);
|
||||||
|
|
||||||
|
return $client;
|
||||||
|
}
|
||||||
|
}
|
@ -19,10 +19,7 @@ use App\Utils\Traits\MakesHash;
|
|||||||
use App\Utils\Traits\MakesMenu;
|
use App\Utils\Traits\MakesMenu;
|
||||||
use App\Utils\Traits\UserSessionAttributes;
|
use App\Utils\Traits\UserSessionAttributes;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use App\Factory\ClientFactory;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Yajra\DataTables\Facades\DataTables;
|
|
||||||
use Yajra\DataTables\Html\Builder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ClientController
|
* Class ClientController
|
||||||
@ -80,16 +77,7 @@ class ClientController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function create(CreateClientRequest $request)
|
public function create(CreateClientRequest $request)
|
||||||
{
|
{
|
||||||
$client = new Client;
|
$client = ClientFactory::create($this->getCurrentCompanyId(), auth()->user()->id);
|
||||||
$client->name = '';
|
|
||||||
$client->company_id = $this->getCurrentCompanyId();
|
|
||||||
$client_contact = new ClientContact;
|
|
||||||
$client_contact->first_name = "";
|
|
||||||
$client_contact->user_id = auth()->user()->id;
|
|
||||||
$client_contact->company_id = $this->getCurrentCompanyId();
|
|
||||||
$client_contact->id = 0;
|
|
||||||
|
|
||||||
$client->contacts->add($client_contact);
|
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'client' => $client,
|
'client' => $client,
|
||||||
|
70
app/Providers/TelescopeServiceProvider.php
Normal file
70
app/Providers/TelescopeServiceProvider.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use Laravel\Telescope\Telescope;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use Laravel\Telescope\IncomingEntry;
|
||||||
|
use Laravel\Telescope\TelescopeApplicationServiceProvider;
|
||||||
|
|
||||||
|
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register any application services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
// Telescope::night();
|
||||||
|
|
||||||
|
$this->hideSensitiveRequestDetails();
|
||||||
|
|
||||||
|
Telescope::filter(function (IncomingEntry $entry) {
|
||||||
|
if ($this->app->isLocal()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entry->isReportableException() ||
|
||||||
|
$entry->isFailedJob() ||
|
||||||
|
$entry->isScheduledTask() ||
|
||||||
|
$entry->hasMonitoredTag();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prevent sensitive request details from being logged by Telescope.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function hideSensitiveRequestDetails()
|
||||||
|
{
|
||||||
|
if ($this->app->isLocal()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Telescope::hideRequestParameters(['_token']);
|
||||||
|
|
||||||
|
Telescope::hideRequestHeaders([
|
||||||
|
'cookie',
|
||||||
|
'x-csrf-token',
|
||||||
|
'x-xsrf-token',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the Telescope gate.
|
||||||
|
*
|
||||||
|
* This gate determines who can access Telescope in non-local environments.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function gate()
|
||||||
|
{
|
||||||
|
Gate::define('viewTelescope', function ($user) {
|
||||||
|
return in_array($user->email, [
|
||||||
|
//
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user