:3
This commit is contained in:
73
app/Http/Controllers/CompanyController.php
Normal file
73
app/Http/Controllers/CompanyController.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Company;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Requests\CompanyRequest;
|
||||
|
||||
class CompanyController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$companies = Company::paginate(10);
|
||||
return view('companies.index', compact('companies'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('companies.create');
|
||||
}
|
||||
|
||||
public function store(CompanyRequest $request)
|
||||
{
|
||||
// Store the validated data from the form
|
||||
$validatedData = $request->validated();
|
||||
|
||||
// Handle the logo upload if it exists
|
||||
if ($request->hasFile('logo')) {
|
||||
$logoPath = $request->file('logo')->store('logos', 'public');
|
||||
$validatedData['logo'] = $logoPath;
|
||||
}
|
||||
|
||||
// Create the company with the validated data
|
||||
$company = \App\Models\Company::create($validatedData);
|
||||
|
||||
// Redirect or return a response
|
||||
return redirect()->route('companies.index')->with('success', 'Company created successfully.');
|
||||
}
|
||||
|
||||
public function show(Company $company)
|
||||
{
|
||||
return view('companies.show', compact('company'));
|
||||
}
|
||||
|
||||
public function edit(Company $company)
|
||||
{
|
||||
return view('companies.edit', compact('company'));
|
||||
}
|
||||
|
||||
public function update(CompanyRequest $request, Company $company)
|
||||
{
|
||||
// Store the validated data from the form
|
||||
$validatedData = $request->validated();
|
||||
|
||||
// Handle the logo upload if it exists
|
||||
if ($request->hasFile('logo')) {
|
||||
$logoPath = $request->file('logo')->store('logos', 'public');
|
||||
$validatedData['logo'] = $logoPath;
|
||||
}
|
||||
|
||||
// Update the company with the validated data
|
||||
$company->update($validatedData);
|
||||
|
||||
// Redirect or return a response
|
||||
return redirect()->route('companies.index')->with('success', 'Company updated successfully.');
|
||||
}
|
||||
|
||||
public function destroy(Company $company)
|
||||
{
|
||||
$company->delete();
|
||||
return redirect()->route('companies.index')->with('success', 'Company deleted successfully.');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user