-
Notifications
You must be signed in to change notification settings - Fork 49
Basic CRUD
JP Barbosa edited this page Mar 11, 2016
·
3 revisions
php artisan make:model Article --migration
nano database/migrations/*create_articles_table.php
...
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('content');
$table->timestamps();
});
}
...
php artisan migrate
nano app/Article.php
class Article extends Model
{
protected $fillable = ['title', 'content'];
}
php artisan tinker
App\Article::create(['title' => 'Article Title', 'content' => 'Article Content']);
php artisan make:controller ArticlesController
nano app/Http/Controllers/ArticlesController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Article;
class ArticlesController extends Controller
{
public function index()
{
return Article::all();
}
public function store(Request $request)
{
return Article::create($request->all());
}
public function show(Article $article)
{
return $article;
}
public function update(Request $request, Article $article)
{
$article->update($request->all());
return $article;
}
public function destroy(Article $article)
{
return (string) $article->delete();
}
}
nano app/Http/routes.php
Route::singularResourceParameters();
...
Route::resource('articles', 'ArticlesController');
php artisan serve
curl -H "Accept: application/json" \
http://localhost:8000/articles \
--data "title=Article Title" \
--data "content=Article Content"
{"title":"Article Title","content":"Article Content"...}
curl -H "Accept: application/json" http://localhost:8000/articles
curl -H "Accept: application/json" http://localhost:8000/articles/1
curl -X PATCH \
-H "Accept: application/json" \
--data "title=Edited Article Title" \
http://localhost:8000/articles/1
curl -X DELETE \
-H "Accept: application/json" \
http://localhost:8000/articles/1
git add .
git commit -m "Add articles basic CRUD"
Next step: Validation
- Setup
- Basic CRUD
- Validation
- Views
- Association
- Association Controller
- Association Views
- Basic Template
- Bootstrap
- Bootstrap CRUD
- Alerts
- Welcome Page
- Ajax CRUD
- Send Email
- Send Email Views
- Jobs Queue
- Captcha
- Async External Content
- Cached External Content
- Tests Setup
- Functional Tests
- Acceptance Tests
- Continuous Integration
- Deploy with Heroku
- Deploy with Forge
- Update README