Added visibled checkbox and little changes

This commit is contained in:
Kamil Niemczycki 2022-02-16 11:12:42 +01:00
parent b4e14b3151
commit 1d89f724f9
7 changed files with 35 additions and 12 deletions

View File

@ -14,7 +14,9 @@ class ProjectController
public function __construct( public function __construct(
private ProjectRepository $projectRepository private ProjectRepository $projectRepository
) {} ) {
$this->projectRepository->auth = true;
}
public function edit(Project $project): View public function edit(Project $project): View
{ {

View File

@ -32,6 +32,7 @@ class ProjectRequest extends FormRequest
'project_url' => 'nullable|string', 'project_url' => 'nullable|string',
'project_version' => 'nullable|string', 'project_version' => 'nullable|string',
'description' => 'nullable|string', 'description' => 'nullable|string',
'visible' => 'nullable|in:yes,1,true,on'
]; ];
} }
} }

View File

@ -24,7 +24,7 @@ class ProjectResource extends JsonResource
'author' => $this->author, 'author' => $this->author,
'images' => $this->images, 'images' => $this->images,
'release_date' => $this->release_date, 'release_date' => $this->release_date,
'update_date' => $this->release_date, 'update_date' => $this->update_date,
'project_url' => $this->project_url, 'project_url' => $this->project_url,
'project_version' => $this->project_version, 'project_version' => $this->project_version,
'description' => $this->description, 'description' => $this->description,

View File

@ -4,9 +4,9 @@ declare(strict_types=1);
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Database\Eloquent\Builder;
/** /**
* @property int $id * @property int $id
@ -38,7 +38,8 @@ class Project extends Model
'update_date' => 'datetime:Y-m-d', 'update_date' => 'datetime:Y-m-d',
'project_url' => 'string', 'project_url' => 'string',
'project_version' => 'string', 'project_version' => 'string',
'description' => 'string' 'description' => 'string',
'visible' => 'boolean'
]; ];
public function getReleaseDateAttribute($value): String public function getReleaseDateAttribute($value): String
@ -64,4 +65,9 @@ class Project extends Model
$this->attributes['update_date'] = null; $this->attributes['update_date'] = null;
} }
public function scopeVisibled(Builder $builder)
{
return $builder->where('visible', true);
}
} }

View File

@ -8,12 +8,13 @@ use App\Http\Resources\ProjectCollection;
use App\Http\Resources\ProjectResource; use App\Http\Resources\ProjectResource;
use App\Models\Project; use App\Models\Project;
use App\Repository\Interfaces\ProjectRepository as ProjectRepositoryInterface; use App\Repository\Interfaces\ProjectRepository as ProjectRepositoryInterface;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
class ProjectRepository implements ProjectRepositoryInterface class ProjectRepository implements ProjectRepositoryInterface
{ {
public bool $auth = false;
public function __construct( public function __construct(
private Project $project private Project $project
) {} ) {}
@ -22,17 +23,23 @@ class ProjectRepository implements ProjectRepositoryInterface
{ {
$project = $this->project $project = $this->project
->query() ->query()
->orderBy('release_data', 'ASC') ->orderBy('release_data', 'ASC');
->get();
return (new ProjectCollection($project))->collection; if (!$this->auth)
$project->visibled();
return (new ProjectCollection($project->get()))->collection;
} }
public function get(int $id): ProjectResource public function get(int $id): ProjectResource
{ {
$project = $this->project $project = $this->project
->query() ->query();
->findOrFail($id);
return new ProjectResource($project); if (!$this->auth)
$project->visibled();
return new ProjectResource($project->findOrFail($id));
} }
public function update(Project $project, array $data = []): bool public function update(Project $project, array $data = []): bool
@ -87,6 +94,12 @@ class ProjectRepository implements ProjectRepositoryInterface
else else
$toSave['update_date'] = null; $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; return $toSave;
} }

View File

@ -27,6 +27,7 @@ class CreateProjectsTable extends Migration
$table->string('project_url', 255)->nullable()->default(null); $table->string('project_url', 255)->nullable()->default(null);
$table->string('project_version', 20)->nullable()->default(null); $table->string('project_version', 20)->nullable()->default(null);
$table->text('description')->nullable()->default(null); $table->text('description')->nullable()->default(null);
$table->boolean('visible')->nullable()->default(false);
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@ -68,7 +68,7 @@
<div class="check-place"> <div class="check-place">
<label for="visible">Visible</label> <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> </div>
<input type="submit" value="Aktualizuj"> <input type="submit" value="Aktualizuj">