public function store($companyId, $request)
 {
     $cacheTag = ['companies', 'company' . $companyId, 'domains'];
     $cacheKey = 'index';
     $_companies = Companies::find($companyId);
     if ($_companies) {
         if (!empty($request['domains'])) {
             foreach ($request['domains'] as $value) {
                 if (strpos($value, 'localhost') !== 0) {
                     $validator = $this->validate($value);
                     if ($validator->fails()) {
                         return new \Exception($validator->errors()->first());
                     }
                 }
                 if (Domains::where('domain', '=', $value)->where('company_id', '<>', $companyId)->count() > 0) {
                     return new \Exception('O domínio ' . $value . ' já está sendo usado por outro company');
                 }
             }
             $_companies->domains()->delete();
             foreach ($request['domains'] as $value) {
                 Logs::create(['activity' => 'store', 'module' => 'companies_domains', 'ref' => $value]);
                 $_companies->domains()->create(['company_id' => $companyId, 'domain' => $value]);
             }
             Cache::tags($cacheTag)->flush();
             return true;
         } else {
             return true;
         }
     } else {
         return new \Exception("Houve um erro ao localizar registro (id not found)");
     }
 }
 public function destroy($companyId, $managerId)
 {
     $cacheTag = ['companies', 'company' . $companyId, 'managers'];
     $_company = Companies::find($companyId);
     if ($_company) {
         $_manager = $_company->managers()->select(['id'])->where('id', '=', $managerId);
         if ($_manager->count() > 0) {
             Cache::tags($cacheTag)->flush();
             Logs::create(['activity' => 'destroy', 'module' => 'companies_managers', 'ref' => $managerId]);
             return $_company->managers()->detach($_manager->first()->id);
         } else {
             return new \Exception("Houve um erro ao localizar registro (manager not found)");
         }
     } else {
         return new \Exception("Houve um erro ao localizar registro (id not found)");
     }
 }
 public function fields(Request $request)
 {
     $company = config('global.companies.current.name');
     $managers = config('global.companies.current.managers');
     if ($request->get('data')) {
         Mail::send('emails.fields', ['data' => $request->get('data')], function ($message) use($managers, $company) {
             $message->from("*****@*****.**", $company)->subject("Você recebeu uma nova mensagem através do site.");
             foreach ($managers as $manager) {
                 $message->to($manager['email']);
             }
         });
         if (count(Mail::failures()) === 0) {
             Logs::create(['activity' => 'store', 'module' => 'emails', 'ref' => config('global.companies.current.id')]);
             return $this->jsonResponse();
         } else {
             return $this->jsonDataResponse(new \Exception('Tivemos um problema ao enviar email'));
         }
     } else {
         return $this->jsonDataResponse(new \Exception('Houve um erro ao enviar seu email, tente novamente mais tarde (no data)'));
     }
 }
 public function store($request)
 {
     $cacheTag = ['configurations'];
     $validator = $this->validate($request);
     if (!$validator->fails()) {
         $_model = Configurations::getConfigutationsByCompanyId(config('global.companies.current.id'));
         if ($_model) {
             Logs::create(['activity' => 'update', 'module' => 'configurations']);
             Cache::tags(['delivery'])->flush();
             Cache::tags($cacheTag)->flush();
             if ($_model->company_id === config('global.companies.current.id')) {
                 return $_model->update($request);
             } else {
                 return new \Exception("Você não tem permissão para atualizar este registro");
             }
         } else {
             return new \Exception("Houve um erro ao localizar registro (id not found)");
         }
     } else {
         return new \Exception($validator->errors()->first());
     }
 }
 public function image($request)
 {
     if (!empty($request->product_id)) {
         $_model = Products::find($request->product_id);
         if ($request->hasFile('file')) {
             $_file = $request->file('file');
             if ($_model->image) {
                 Storage::delete($_model->image);
             }
             $filename = md5(time() . $_file->getClientOriginalName() . $request->product_id) . '.' . $_file->guessClientExtension();
             $request->file('file')->move(config('filesystems.disks.local.root'), $filename);
             $_model->image = $filename;
             $_model->save();
             Logs::create(['activity' => 'image', 'module' => 'products']);
             Cache::tags(['products'])->flush();
             return true;
         } else {
             return new \Exception("Parece que você não selecionou nenhum arquivo");
         }
     } else {
         return new \Exception("Produto não encontrado.");
     }
 }
Example #6
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    \App\Models\Logs::create();
    return view('welcome');
});
/*FILES*/
Route::get('files/{filename}', 'Files\\IndexController@index');
Route::get('image/{filename}', 'Files\\IndexController@image');
Route::group(['middleware' => ['getCompany', 'getManager', 'getUser']], function () {
    /*EMAILS*/
    Route::post('emails/fields', 'Emails\\IndexController@fields');
    Route::post('emails', 'Emails\\IndexController@index');
    /*STATUS*/
    Route::get('status', 'Status\\IndexController@index');
    Route::get('status/database', 'Status\\IndexController@database');
    Route::get('status/cache', 'Status\\IndexController@cache');
    Route::get('status/emails', 'Status\\IndexController@emails');
    Route::get('status/checkouts', 'Status\\IndexController@checkouts');
    Route::get('status/categories', 'Status\\IndexController@categories');
    Route::get('status/products', 'Status\\IndexController@products');
 public function destroy($id)
 {
     $cacheTag = ['companies'];
     if ($this->isManager($id)) {
         $_model = Companies::find($id);
         if ($_model) {
             Logs::create(['activity' => 'destroy', 'module' => 'companies', 'ref' => $id]);
             Cache::tags($cacheTag)->flush();
             return $_model->delete();
         } else {
             return new \Exception("Houve um erro ao localizar registro (id not found)");
         }
     } else {
         return new \Exception('Você não tem permissão para realizar esta ação >:(');
     }
 }
 public function destroy($id)
 {
     $cacheTag = ['checkouts'];
     $_model = Checkouts::find($id);
     if ($_model) {
         Logs::create(['activity' => 'destroy', 'module' => 'checkouts', 'ref' => $id]);
         Cache::tags($cacheTag)->flush();
         if ($_model->company_id === config('global.companies.current.id')) {
             return $_model->delete();
         } else {
             return new \Exception("Você não tem permissão para realizar esta ação");
         }
     } else {
         return new \Exception("Houve um erro ao localizar registro (id not found)");
     }
 }
 public function destroy($id)
 {
     $cacheTag = ['managers'];
     $_model = Managers::find($id);
     if ($_model) {
         Logs::create(['activity' => 'destroy', 'module' => 'profile']);
         Cache::tags($cacheTag)->flush();
         return $_model->delete();
     } else {
         return new \Exception("Houve um erro ao localizar registro (id not found)");
     }
 }
 public function destroy($userId, $addressId)
 {
     $cacheTag = ['users', 'user' . $userId, 'address'];
     $_user = Users::find($userId);
     if ($_user) {
         $_address = $_user->address()->select(['id'])->where('id', '=', $addressId);
         if ($_address->count() > 0) {
             Cache::tags($cacheTag)->flush();
             Logs::create(['activity' => 'destroy', 'module' => 'users_address', 'ref' => $addressId]);
             return $_address->delete();
         } else {
             return new \Exception("Houve um erro ao localizar registro (address not found)");
         }
     } else {
         return new \Exception("Houve um erro ao localizar registro (id not found)");
     }
 }