initial commit
This commit is contained in:
93
app/Http/Controllers/RateCardController.php
Normal file
93
app/Http/Controllers/RateCardController.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\RateCard;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class RateCardController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$rateCards = RateCard::orderBy('sort_order')->orderBy('platform')->get();
|
||||
return view('rate-cards.index', compact('rateCards'));
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
return view('rate-cards.create');
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'service_name' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'platform' => 'required|in:instagram,tiktok,youtube,general',
|
||||
'content_type' => 'nullable|string|max:50',
|
||||
'price' => 'required|numeric|min:0',
|
||||
'currency' => 'required|string|max:10',
|
||||
'price_unit' => 'required|in:per_content,per_month,per_campaign',
|
||||
'is_negotiable' => 'boolean',
|
||||
'sort_order' => 'nullable|integer',
|
||||
]);
|
||||
|
||||
$validated['is_negotiable'] = $request->boolean('is_negotiable');
|
||||
$validated['is_active'] = true;
|
||||
|
||||
RateCard::create($validated);
|
||||
|
||||
return redirect()->route('rate-cards.index')
|
||||
->with('success', '💰 Rate card entry added!');
|
||||
}
|
||||
|
||||
public function edit(RateCard $rateCard): View
|
||||
{
|
||||
return view('rate-cards.edit', compact('rateCard'));
|
||||
}
|
||||
|
||||
public function update(Request $request, RateCard $rateCard): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'service_name' => 'required|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'platform' => 'required|in:instagram,tiktok,youtube,general',
|
||||
'content_type' => 'nullable|string|max:50',
|
||||
'price' => 'required|numeric|min:0',
|
||||
'currency' => 'required|string|max:10',
|
||||
'price_unit' => 'required|in:per_content,per_month,per_campaign',
|
||||
'is_negotiable' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'nullable|integer',
|
||||
]);
|
||||
|
||||
$validated['is_negotiable'] = $request->boolean('is_negotiable');
|
||||
$validated['is_active'] = $request->boolean('is_active');
|
||||
|
||||
$rateCard->update($validated);
|
||||
|
||||
return redirect()->route('rate-cards.index')
|
||||
->with('success', '💰 Rate card updated!');
|
||||
}
|
||||
|
||||
public function destroy(RateCard $rateCard): RedirectResponse
|
||||
{
|
||||
$rateCard->delete();
|
||||
return redirect()->route('rate-cards.index')->with('success', 'Entry removed.');
|
||||
}
|
||||
|
||||
public function public(): View
|
||||
{
|
||||
$rateCards = RateCard::where('is_active', true)
|
||||
->orderBy('sort_order')
|
||||
->orderBy('platform')
|
||||
->get()
|
||||
->groupBy('platform');
|
||||
|
||||
return view('rate-cards.public', compact('rateCards'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user