Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add projects #87

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace App\Http\Controllers;

use App\Models\Project;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Illuminate\View\View;

class ProjectController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
seo()->title('Projects - '.config('app.name'));
$projects = Project::active()->orderByDesc('start_date')->paginate(12);

return view('projects.index', compact('projects'));
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}

public function show($param): View
{
$project = Project::where('uuid', $param)
->orWhere('slug', $param)
->active()
->firstOrFail();
abort_if(! $project, 404);
views($project)->cooldown(60)->record();

seo()->title($project->title.' - Projects - '.config('app.name'));
seo()->description(strip_tags(Str::of(Str::limit($project->content, 150))->markdown()));

return view('project.show', compact('project'));
}

/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}
64 changes: 64 additions & 0 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace App\Models;

use CyrildeWit\EloquentViewable\Contracts\Viewable;
use CyrildeWit\EloquentViewable\InteractsWithViews;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
use Kilobyteno\LaravelUserGuestLike\Traits\HasUserGuestLike;
use Spatie\Tags\HasTags;

class Project extends Model implements Viewable
{
use HasFactory;
use HasTags;
use HasUserGuestLike;
use InteractsWithViews;
use SoftDeletes;

public static function boot(): void
{
parent::boot();

self::creating(function ($model) {
$model->uuid = Str::uuid()->toString();
$model->slug = Str::slug($model->title);
});

self::updating(function ($model) {
if (! $model->uuid) {
$model->uuid = Str::uuid()->toString();
}
$model->slug = Str::slug($model->title);
});
}

protected $fillable = [
'title',
'slug',
'content',
'repository',
'website',
'logo_url',
'start_date',
'end_date',
'status',
];

protected $casts = [
'start_date' => 'date',
'end_date' => 'date',
];

protected $withCount = [
'likes',
];

public function scopeActive($query)
{
return $query->where('status', '>=', 1);
}
}
Loading
Loading