Added visibled checkbox and little changes
This commit is contained in:
parent
b4e14b3151
commit
1d89f724f9
@ -14,7 +14,9 @@ class ProjectController
|
||||
|
||||
public function __construct(
|
||||
private ProjectRepository $projectRepository
|
||||
) {}
|
||||
) {
|
||||
$this->projectRepository->auth = true;
|
||||
}
|
||||
|
||||
public function edit(Project $project): View
|
||||
{
|
||||
|
@ -32,6 +32,7 @@ class ProjectRequest extends FormRequest
|
||||
'project_url' => 'nullable|string',
|
||||
'project_version' => 'nullable|string',
|
||||
'description' => 'nullable|string',
|
||||
'visible' => 'nullable|in:yes,1,true,on'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class ProjectResource extends JsonResource
|
||||
'author' => $this->author,
|
||||
'images' => $this->images,
|
||||
'release_date' => $this->release_date,
|
||||
'update_date' => $this->release_date,
|
||||
'update_date' => $this->update_date,
|
||||
'project_url' => $this->project_url,
|
||||
'project_version' => $this->project_version,
|
||||
'description' => $this->description,
|
||||
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@ -38,7 +38,8 @@ class Project extends Model
|
||||
'update_date' => 'datetime:Y-m-d',
|
||||
'project_url' => 'string',
|
||||
'project_version' => 'string',
|
||||
'description' => 'string'
|
||||
'description' => 'string',
|
||||
'visible' => 'boolean'
|
||||
];
|
||||
|
||||
public function getReleaseDateAttribute($value): String
|
||||
@ -64,4 +65,9 @@ class Project extends Model
|
||||
$this->attributes['update_date'] = null;
|
||||
}
|
||||
|
||||
public function scopeVisibled(Builder $builder)
|
||||
{
|
||||
return $builder->where('visible', true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,12 +8,13 @@ use App\Http\Resources\ProjectCollection;
|
||||
use App\Http\Resources\ProjectResource;
|
||||
use App\Models\Project;
|
||||
use App\Repository\Interfaces\ProjectRepository as ProjectRepositoryInterface;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class ProjectRepository implements ProjectRepositoryInterface
|
||||
{
|
||||
|
||||
public bool $auth = false;
|
||||
|
||||
public function __construct(
|
||||
private Project $project
|
||||
) {}
|
||||
@ -22,17 +23,23 @@ class ProjectRepository implements ProjectRepositoryInterface
|
||||
{
|
||||
$project = $this->project
|
||||
->query()
|
||||
->orderBy('release_data', 'ASC')
|
||||
->get();
|
||||
return (new ProjectCollection($project))->collection;
|
||||
->orderBy('release_data', 'ASC');
|
||||
|
||||
if (!$this->auth)
|
||||
$project->visibled();
|
||||
|
||||
return (new ProjectCollection($project->get()))->collection;
|
||||
}
|
||||
|
||||
public function get(int $id): ProjectResource
|
||||
{
|
||||
$project = $this->project
|
||||
->query()
|
||||
->findOrFail($id);
|
||||
return new ProjectResource($project);
|
||||
->query();
|
||||
|
||||
if (!$this->auth)
|
||||
$project->visibled();
|
||||
|
||||
return new ProjectResource($project->findOrFail($id));
|
||||
}
|
||||
|
||||
public function update(Project $project, array $data = []): bool
|
||||
@ -87,6 +94,12 @@ class ProjectRepository implements ProjectRepositoryInterface
|
||||
else
|
||||
$toSave['update_date'] = null;
|
||||
|
||||
if (
|
||||
isset($data['visible']) &&
|
||||
in_array($data['visible'], ['yes', 'on', 1, true])
|
||||
) $toSave['visible'] = true;
|
||||
else $toSave['visible'] = false;
|
||||
|
||||
return $toSave;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ class CreateProjectsTable extends Migration
|
||||
$table->string('project_url', 255)->nullable()->default(null);
|
||||
$table->string('project_version', 20)->nullable()->default(null);
|
||||
$table->text('description')->nullable()->default(null);
|
||||
$table->boolean('visible')->nullable()->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
@ -68,7 +68,7 @@
|
||||
|
||||
<div class="check-place">
|
||||
<label for="visible">Visible</label>
|
||||
<input id="visible" type="checkbox" name="visible" {{ old('visible') != 0 ? 'checked' : '' }}>
|
||||
<input id="visible" type="checkbox" name="visible" {{ old('visible', $project->visible) != 0 ? 'checked' : '' }}>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Aktualizuj">
|
||||
|
Loading…
x
Reference in New Issue
Block a user