first commit from hostslim
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Segment;
|
||||
use App\Models\Website;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class SegmentController extends Controller
|
||||
{
|
||||
public function index(Website $website): View
|
||||
{
|
||||
$this->authorize('view', $website);
|
||||
|
||||
return view('segments.index', [
|
||||
'website' => $website,
|
||||
'segments' => $website->segments()->orderBy('name')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Website $website): View
|
||||
{
|
||||
$this->authorize('view', $website);
|
||||
|
||||
return view('segments.create', ['website' => $website]);
|
||||
}
|
||||
|
||||
public function store(Request $request, Website $website): RedirectResponse
|
||||
{
|
||||
$this->authorize('view', $website);
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'filters' => 'required|array|min:1',
|
||||
'filters.*.field' => 'required|string|in:country,region,city,browser,os,device_type,language,screen_resolution',
|
||||
'filters.*.operator' => 'required|string|in:=,!=,contains,starts_with',
|
||||
'filters.*.value' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
$website->segments()->create($validated);
|
||||
|
||||
return redirect()
|
||||
->route('segments.index', $website)
|
||||
->with('success', 'Segment created successfully.');
|
||||
}
|
||||
|
||||
public function edit(Website $website, Segment $segment): View
|
||||
{
|
||||
$this->authorize('view', $website);
|
||||
|
||||
return view('segments.edit', [
|
||||
'website' => $website,
|
||||
'segment' => $segment,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Website $website, Segment $segment): RedirectResponse
|
||||
{
|
||||
$this->authorize('view', $website);
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'filters' => 'required|array|min:1',
|
||||
'filters.*.field' => 'required|string|in:country,region,city,browser,os,device_type,language,screen_resolution',
|
||||
'filters.*.operator' => 'required|string|in:=,!=,contains,starts_with',
|
||||
'filters.*.value' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
$segment->update($validated);
|
||||
|
||||
return redirect()
|
||||
->route('segments.index', $website)
|
||||
->with('success', 'Segment updated successfully.');
|
||||
}
|
||||
|
||||
public function destroy(Website $website, Segment $segment): RedirectResponse
|
||||
{
|
||||
$this->authorize('view', $website);
|
||||
|
||||
$segment->delete();
|
||||
|
||||
return redirect()
|
||||
->route('segments.index', $website)
|
||||
->with('success', 'Segment deleted.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user