Файл: app/Http/Controllers/WebsiteController.php
Строк: 68
<?php
namespace AppHttpControllers;
use AppTraitsDateRangeTrait;
use AppModelsWebsite;
use AppHttpRequestsStoreWebsiteRequest;
use AppHttpRequestsUpdateWebsiteRequest;
use AppTraitsWebsiteTrait;
use IlluminateHttpRequest;
class WebsiteController extends Controller
{
use WebsiteTrait, DateRangeTrait;
/**
* Show the create Website form.
*
* @return IlluminateContractsFoundationApplication|IlluminateContractsViewFactory|IlluminateViewView
*/
public function create()
{
return view('websites.container', ['view' => 'new']);
}
/**
* Show the edit Website form.
*
* @param Request $request
* @param $id
* @return IlluminateContractsFoundationApplication|IlluminateContractsViewFactory|IlluminateViewView
*/
public function edit(Request $request, $id)
{
$website = Website::where([['id', '=', $id], ['user_id', '=', $request->user()->id]])->firstOrFail();
return view('websites.container', ['view' => 'edit', 'website' => $website]);
}
/**
* Store the Website.
*
* @param StoreWebsiteRequest $request
* @return IlluminateHttpRedirectResponse
*/
public function store(StoreWebsiteRequest $request)
{
$this->websiteStore($request);
$request->user()->has_websites = true;
$request->user()->save();
return redirect()->route('dashboard')->with('success', __(':name has been created.', ['name' => $request->input('domain')]));
}
/**
* Update the Website.
*
* @param UpdateWebsiteRequest $request
* @param $id
* @return IlluminateHttpRedirectResponse
*/
public function update(UpdateWebsiteRequest $request, $id)
{
$website = Website::where([['id', '=', $id], ['user_id', '=', $request->user()->id]])->firstOrFail();
$this->websiteUpdate($request, $website);
return back()->with('success', __('Settings saved.'));
}
/**
* Delete the Website.
*
* @param Request $request
* @param $id
* @return IlluminateHttpRedirectResponse
* @throws Exception
*/
public function destroy(Request $request, $id)
{
$website = Website::where([['id', '=', $id], ['user_id', '=', $request->user()->id]])->firstOrFail();
$website->delete();
$request->user()->has_websites = Website::where('user_id', '=', $request->user()->id)->count() > 0;
$request->user()->save();
return redirect()->route('dashboard')->with('success', __(':name has been deleted.', ['name' => $website->domain]));
}
}