agregada la opcion de published a los posts
This commit is contained in:
@@ -9,8 +9,11 @@ class BlogController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$posts = Post::where('is_published', true)
|
||||
->orderBy('created_at', 'desc')
|
||||
->take(3)
|
||||
->get();
|
||||
|
||||
$posts = Post::orderBy('created_at', 'desc')->take(3)->get();
|
||||
return view('blog.index', ['posts' => $posts] );
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ class PostController extends Controller
|
||||
$post = new Post();
|
||||
$post->title = $request->title;
|
||||
$post->md = $request->md;
|
||||
$post->is_published = $request->has('published');
|
||||
$post->save();
|
||||
|
||||
return redirect()->route('admin.post.index');
|
||||
@@ -41,6 +42,7 @@ class PostController extends Controller
|
||||
|
||||
$post->title = $request->title;
|
||||
$post->md = $request->md;
|
||||
$post->is_published = $request->has('published');
|
||||
$post->update();
|
||||
|
||||
return redirect()->route('admin.post.index');
|
||||
|
||||
@@ -7,6 +7,7 @@ use Faker\Generator as Faker;
|
||||
$factory->define(App\Post::class, function (Faker $faker) {
|
||||
return [
|
||||
'title' => $faker->words(5, true),
|
||||
'md' => $faker->paragraphs(10, true)
|
||||
'md' => $faker->paragraphs(10, true),
|
||||
'is_published' => $faker->boolean
|
||||
];
|
||||
});
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreatePublishedRow extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('posts', function (Blueprint $table) {
|
||||
$table->boolean('is_published')
|
||||
->after('md')
|
||||
->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::table('posts', function (Blueprint $table) {
|
||||
$table->dropColumn('is_published');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,11 @@
|
||||
<label for="md">Content</label>
|
||||
<textarea id="md" name="md"></textarea>
|
||||
|
||||
<label for="published">
|
||||
<input type="checkbox" id="published" name="published"/>
|
||||
Published
|
||||
</label>
|
||||
|
||||
<div class="control">
|
||||
<button class="pure-button button-black-white" name="action" id="preview" type="submit" value="preview">Preview</button>
|
||||
<button class="pure-button button-black-white" name="action" id="main" type="submit" value="create">Create</button>
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
<label for="md">Content</label>
|
||||
<textarea id="md" name="md">{{ old('md', $post->md) }}</textarea>
|
||||
|
||||
<label for="published">
|
||||
<input type="checkbox" id="published" name="published" value="{{ old('published', $post->is_published) }}"/>
|
||||
Published
|
||||
</label>
|
||||
|
||||
<div class="control">
|
||||
<button class="pure-button button-black-white" name="action" id="preview" type="submit" value="preview">Preview</button>
|
||||
<button class="pure-button button-black-white" name="action" id="main" type="submit" value="update">Update</button>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Title</th>
|
||||
<th>Published</th>
|
||||
<th>Date</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
@@ -19,6 +20,7 @@
|
||||
<tr>
|
||||
<td>{{$post->id}}</td>
|
||||
<td>{{ Str::limit($post->title, 30, "...") }}</td>
|
||||
<td>{{$post->is_published ? "Yes" : "No"}}</td>
|
||||
<td>{{$post->created_at->format('Y-m-d')}}</td>
|
||||
<td class="controls">
|
||||
<a href="{{ route('admin.post.edit', ['post' => $post->id]) }}" class="pure-button button-black-white">Edit</a>
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
<label for="md">Description</label>
|
||||
<textarea id="md" name="md"></textarea>
|
||||
|
||||
<label for="published">
|
||||
<input type="checkbox" id="published" name="published"/>
|
||||
Published
|
||||
</label>
|
||||
|
||||
<div class="control">
|
||||
<button class="pure-button button-black-white" name="action" id="preview" type="submit" value="preview">Preview</button>
|
||||
<button class="pure-button button-black-white" name="action" id="main" type="submit" value="create">Create</button>
|
||||
|
||||
Reference in New Issue
Block a user