Skip to content

Instantly share code, notes, and snippets.

View Mombuyish's full-sized avatar
Never stop progressing.

Yish Mombuyish

Never stop progressing.
View GitHub Profile
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
@foreach($posts as $post)
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<img src="{{ $post->name }}">
<?php
public function store(Request $request)
{
$post = $this->postService->create($request->all());
return redirect()->to(route('posts.show', $post->id))->with('message', 'Created Successful.');
}
<?php
namespace App\Entities;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $fillable = [
'subject', 'description', 'status'
<?php
public function create($attributes)
{
//用 laravel relations 的方式建立文章
//也可以透過 repository 的方式做建立或將此搬遷過去
$post = auth()->user()->posts()->create($attributes);
//設定 slug, 加入標籤
$post->slugify()->tag($attributes['tag']);
<?php
public function getBy($id)
{
return $this->model->by($id)->get();
}
public function getByUser($user_id)
{
return $this->model->byUser($user_id)->get();
<?php
....
protected function mapApiRoutes()
{
Route::middleware('api')
//跟 laravel 說你要他是 subdomain, 也可以寫成 'api.' . env('APP_URL')
->domain('api.blog.dev')
->namespace($this->namespace)
<?php
public function getStatusAttribute($value)
{
switch ($value) {
case 1:
return 'published';
case 2:
return 'top';
default:
<?php
namespace App\Presenters;
class PostPresenter
{
public function status($value)
{
switch ($value) {
case 1:
@extends('layouts.app')
@inject('PostPresenter', 'App\Presenters\PostPresenter')
@section('content')
<h1>All posts</h1>
@foreach($posts as $post)
<div>
<?php
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()