7d854ffb0a
- Translation system: lang/es/ PHP files (auth, validation, pagination, passwords)
- Rappasoft vendor translations published (lang/vendor/livewire-tables/es/)
- JSON files synced to 391 keys (EN + ES, full parity)
- APP_LOCALE changed to 'es', users.locale column default changed to 'es'
- Language switcher fixed: JS event + window.location.reload() avoids /livewire/update redirect
- SetLocale middleware fallback uses config('app.locale') instead of hardcoded 'en'
- setSortingPillsEnabled(false) on ProjectTable, CompanyTable, UserTable
- Translated 17 blade views: project-map, template-manager, layer-manager,
company-management, phase-list, media-manager, reports-dashboard,
client-projects, layer-upload, project-form, project-map-editor-tab,
admin/users, projects/media, projects/templates, layouts/client
- Navigation 'Empresas' link uses __('Companies')
- Fixed typo key 'Fases and layers' -> 'Phases and layers'
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
76 lines
1.8 KiB
PHP
76 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Project extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'name', 'reference', 'address', 'country', 'lat', 'lng',
|
|
'start_date', 'end_date_estimated', 'status', 'created_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
"start_date" => "date",
|
|
"end_date_estimated" => "date",
|
|
];
|
|
|
|
public function changeOrders()
|
|
{
|
|
return $this->hasMany(ChangeOrder::class);
|
|
}
|
|
|
|
// Relationships
|
|
public function phases()
|
|
{
|
|
return $this->hasMany(Phase::class)->orderBy('order');
|
|
}
|
|
|
|
public function layers()
|
|
{
|
|
return $this->hasMany(Layer::class);
|
|
}
|
|
|
|
public function users()
|
|
{
|
|
return $this->belongsToMany(User::class)->withPivot('role_in_project');
|
|
}
|
|
|
|
public function companies()
|
|
{
|
|
return $this->belongsToMany(Company::class, 'company_project')
|
|
->withPivot('role_in_project')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function media()
|
|
{
|
|
return $this->morphMany(Media::class, 'mediable');
|
|
}
|
|
|
|
public function images()
|
|
{
|
|
return $this->morphMany(Media::class, 'mediable')->where('category', 'image');
|
|
}
|
|
|
|
// Scope to filter accessible projects for non-admin users
|
|
public function scopeAccessibleBy($query, User $user)
|
|
{
|
|
if ($user->hasRole('Admin')) {
|
|
return $query;
|
|
}
|
|
return $query->whereHas('users', function ($q) use ($user) {
|
|
$q->where('user_id', $user->id);
|
|
});
|
|
}
|
|
} |