This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 }}"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function store(Request $request) | |
{ | |
$post = $this->postService->create($request->all()); | |
return redirect()->to(route('posts.show', $post->id))->with('message', 'Created Successful.'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Entities; | |
use Illuminate\Database\Eloquent\Model; | |
class Post extends Model | |
{ | |
protected $fillable = [ | |
'subject', 'description', 'status' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function create($attributes) | |
{ | |
//用 laravel relations 的方式建立文章 | |
//也可以透過 repository 的方式做建立或將此搬遷過去 | |
$post = auth()->user()->posts()->create($attributes); | |
//設定 slug, 加入標籤 | |
$post->slugify()->tag($attributes['tag']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function getBy($id) | |
{ | |
return $this->model->by($id)->get(); | |
} | |
public function getByUser($user_id) | |
{ | |
return $this->model->byUser($user_id)->get(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
.... | |
protected function mapApiRoutes() | |
{ | |
Route::middleware('api') | |
//跟 laravel 說你要他是 subdomain, 也可以寫成 'api.' . env('APP_URL') | |
->domain('api.blog.dev') | |
->namespace($this->namespace) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function getStatusAttribute($value) | |
{ | |
switch ($value) { | |
case 1: | |
return 'published'; | |
case 2: | |
return 'top'; | |
default: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Presenters; | |
class PostPresenter | |
{ | |
public function status($value) | |
{ | |
switch ($value) { | |
case 1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('layouts.app') | |
@inject('PostPresenter', 'App\Presenters\PostPresenter') | |
@section('content') | |
<h1>All posts</h1> | |
@foreach($posts as $post) | |
<div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ExampleTest extends TestCase | |
{ | |
/** | |
* A basic test example. | |
* | |
* @return void | |
*/ | |
public function testBasicTest() |