feat: add Projects settings with sub-locations and cascading dropdowns in purchase request modal
- Migration: add project_id FK to settings_locations - Models: ProjectSetting hasMany Location, Location belongsTo ProjectSetting - Settings: /settings/projects page — manage projects and their sub-locations (two-panel UI) - Sidebar: Projects nav item under Settings group - Routes: 7 new settings/projects routes (Admin only) - Modal: project_name and location fields now cascading dropdowns populated from settings_projects/settings_locations Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
1 parent
75e4890a08
commit
7f8ae898d5
9 files changed
+696
-4
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Settings;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Settings\Location;
|
||||
use App\Models\Settings\ProjectSetting;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -10,7 +11,7 @@ class ProjectSettingController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$projects = ProjectSetting::orderBy('name')->get();
|
||||
$projects = ProjectSetting::with('locations')->orderBy('name')->get();
|
||||
return view('settings.projects.index', compact('projects'));
|
||||
}
|
||||
|
||||
@@ -36,4 +37,27 @@ class ProjectSettingController extends Controller
|
||||
$project->delete();
|
||||
return redirect()->route('settings.projects.index')->with('success', 'Project deleted.');
|
||||
}
|
||||
|
||||
public function storeLocation(Request $request, ProjectSetting $project)
|
||||
{
|
||||
$request->validate(['name' => 'required|string|max:255']);
|
||||
$project->locations()->create(['name' => $request->name, 'is_active' => true]);
|
||||
return redirect()->route('settings.projects.index')->with('success', 'Location added.');
|
||||
}
|
||||
|
||||
public function updateLocation(Request $request, ProjectSetting $project, Location $location)
|
||||
{
|
||||
$request->validate(['name' => 'required|string|max:255']);
|
||||
$location->update([
|
||||
'name' => $request->name,
|
||||
'is_active' => $request->boolean('is_active', true),
|
||||
]);
|
||||
return redirect()->route('settings.projects.index')->with('success', 'Location updated.');
|
||||
}
|
||||
|
||||
public function destroyLocation(ProjectSetting $project, Location $location)
|
||||
{
|
||||
$location->delete();
|
||||
return redirect()->route('settings.projects.index')->with('success', 'Location deleted.');
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ class Location extends Model
|
||||
{
|
||||
protected $table = 'settings_locations';
|
||||
|
||||
protected $fillable = ['name', 'is_active'];
|
||||
protected $fillable = ['name', 'project_id', 'is_active'];
|
||||
|
||||
protected $casts = ['is_active' => 'boolean'];
|
||||
|
||||
@@ -16,4 +16,9 @@ class Location extends Model
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
public function project(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Settings\ProjectSetting::class, 'project_id');
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,9 @@ class ProjectSetting extends Model
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
public function locations(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Settings\Location::class, 'project_id');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user