Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

caneara/tipsea

13 stars
3 code files
View caneara/tipsea on GitHub

app/Controllers/Site/TipController.php

Open in GitHub
use App\Models\Tip;
use Inertia\Response;
use App\Responses\Page;
use App\Types\Controller;
use App\Actions\Tip\ShowAction;
use App\Requests\Tip\ShowRequest;
 
class TipController extends Controller
{
public function show(ShowRequest $request, Tip $tip) : Response
{
$page = $request->get('no_embed', false)
? Page::make()->withoutMeta()
: Page::make()->meta($tip);
 
return $page->title($tip->title)
->view('tips.show.index')
->with('tip', $tip = ShowAction::execute($tip))
->with('related', ShowAction::related(user(), $tip))
->with('liked', ShowAction::liked(user(), $tip['id']))
->with('comments', fn() => ShowAction::comments($tip['id']))
->with('follower', ShowAction::follower(user(), $tip['user']))
->with('bookmarked', ShowAction::bookmarked(user(), $tip['id']));
}
}

app/Responses/Page.php

Open in GitHub
use App\Types\Model;
use Inertia\Inertia;
use Inertia\Response;
 
class Page
{
protected string $description = 'The smart way to write, share and discover the latest code tips & tricks.';
 
protected array $meta = [];
 
protected string $robots = '';
 
protected string $title = 'TipSea';
 
protected string $view = '';
 
public function __construct()
{
$this->meta = $this->defaultMetaTags();
 
$this->robots = $this->requiresAuthentication() ? 'NOINDEX, NOFOLLOW' : 'INDEX, FOLLOW';
}
 
public function description(string $text) : static
{
$this->description = $text;
 
return $this;
}
 
protected function defaultMetaTags() : array
{
return [
'title' => $this->title,
'description' => $this->description,
'type' => 'website',
'url' => request()->url(),
'image' => asset('img/card.png'),
'twitter' => [
'type' => 'summary_large_image',
],
];
}
 
protected function requiresAuthentication() : bool
{
$middleware = request()->route()?->controllerMiddleware() ?? [];
 
return in_array('auth', $middleware);
}
 
public static function make() : static
{
return new static();
}
 
public function meta(Model $model) : static
{
$this->meta = Meta::create($model);
 
return $this;
}
 
public function render() : Response
{
Inertia::setRootView('app.index');
 
return Inertia::render($this->view)
->with('title', $this->title)
->withViewData('meta', $this->meta)
->withViewData('title', $this->title)
->withViewData('robots', $this->robots)
->withViewData('description', $this->description);
}
 
public function robots(string $text) : static
{
$this->robots = $text;
 
return $this;
}
 
public function title(string $text) : static
{
$this->title = "TipSea - {$text}";
 
return $this;
}
 
public function view(string $text) : static
{
$this->view = str_replace('.', '/', $text);
 
return $this;
}
 
public function with(string $key, mixed $value) : Response
{
return $this->render()->with($key, $value);
}
 
public function withoutMeta() : static
{
$this->meta = [];
 
return $this;
}
 
public function withViewData(string $key, mixed $value) : Response
{
return $this->render()->withViewData($key, $value);
}
}

resources/vue/pages/tips/view/index.vue

Open in GitHub
<template>
<v-layout>
 
<!-- Header -->
<h2>
Tips
</h2>
 
<!-- Summary -->
<p class="mb-7">
Review your existing code tips or create a new one to share
with the community. You can also schedule the publication
of your tips on TipSea, as well as other social media platforms.
</p>
 
<!-- Toolbar -->
<v-toolbar target="tips"
:showCreationOptions="true">
</v-toolbar>
 
<!-- Empty -->
<v-empty class="-mt-2"
actionLabel="Create Tip"
:visible="! prop('tips.data').length"
message="No tips match your search query"
:actionCommand="() => redirect('tips.create')">
</v-empty>
 
<!-- Tips -->
<v-tips :items="prop('tips')"></v-tips>
 
</v-layout>
</template>
 
<script>
import Layout from '@/layout/index.vue';
import TipComponent from '@/components/tips.vue';
import ToolbarComponent from '@/components/toolbar.vue';
import EmptyComponent from '@caneara/varnish/src/components/empty.vue';
export default
{
components : {
'v-empty' : EmptyComponent,
'v-layout' : Layout,
'v-tips' : TipComponent,
'v-toolbar' : ToolbarComponent,
},
}
</script>

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.