Last active
August 29, 2015 13:55
-
-
Save mdunbavan/8731592 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.scaffold') | |
@section('main') | |
<h1>Create Post</h1> | |
{{ Form::open(array('route' => 'posts.store', 'files' => true)) }} | |
<ul> | |
<li> | |
{{ Form::label('title', 'Title:') }} | |
{{ Form::text('title') }} | |
</li> | |
<li> | |
{{ Form::label('body', 'Body:') }} | |
{{ Form::textarea('body') }} | |
</li> | |
<li> | |
{{ Form::file('picture') }} | |
</li> | |
<li> | |
{{ Form::file( 'photo[]', ['multiple' => true] ) }} | |
</li> | |
<li> | |
{{ Form::submit('Submit', array('class' => 'btn btn-info')) }} | |
</ul> | |
{{ Form::close() }} | |
@if ($errors->any()) | |
<ul> | |
{{ implode('', $errors->all('<li class="error">:message</li>')) }} | |
</ul> | |
@endif | |
@stop |
This file contains hidden or 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
// The model for the gallery images allowing multi file uploads | |
<?php | |
class GalleryImage extends Eloquent { | |
// protected $guarded = array(); | |
// public static $rules = array(); | |
public function __construct(array $attributes = array()) { | |
$this->hasAttachedFile('photo', [ | |
'styles' => [ | |
'thumbnail' => '300x300#' | |
] | |
]); | |
parent::__construct($attributes); | |
} | |
// A gallery image belongs to a post. | |
public function post(){ | |
return $this->belongsTo('Post'); | |
} | |
} |
This file contains hidden or 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 Post extends Eloquent { | |
use Codesleeve\Stapler\Stapler; | |
protected $guarded = array(); | |
// A user has many profile pictures. | |
public function galleryImages(){ | |
return $this->hasMany('GalleryImage'); | |
} | |
public static $rules = array( | |
'title' => 'required', | |
'body' => 'required' | |
); | |
public function __construct(array $attributes = array()) { | |
$this->hasAttachedFile('picture', [ | |
'styles' => [ | |
'thumbnail' => '100x100', | |
'large' => '300x300' | |
], | |
// 'url' => '/system/:attachment/:id_partition/:style/:filename', | |
'default_url' => '/:attachment/:style/missing.jpg' | |
]); | |
parent::__construct($attributes); | |
} | |
} |
This file contains hidden or 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() | |
{ | |
$input = Input::all(); | |
$validation = Validator::make($input, Post::$rules); | |
if ($validation->passes()) | |
{ | |
$this->post->create($input); | |
return Redirect::route('posts.index'); | |
} | |
$post = Post::create(['picture' => Input::file('picture')]); | |
foreach(Input::file('photos') as $photo) | |
{ | |
$galleryImage = new GalleryImage(); | |
$galleryImage->photo = $photo; | |
$user->galleryImages()->save($galleryImage); | |
} | |
return Redirect::route('posts.create') | |
->withInput() | |
->withErrors($validation) | |
->with('message', 'There were validation errors.'); | |
} |
This file contains hidden or 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
36. ErrorException | |
…/vendor/laravel/framework/src/Illuminate/Support/helpers.php916 | |
35. Illuminate\Exception\Handler handleError | |
<#unknown>0 | |
34. preg_replace | |
…/vendor/laravel/framework/src/Illuminate/Support/helpers.php916 | |
33. str_replace_array | |
…/vendor/laravel/framework/src/Illuminate/Database/QueryException.php53 | |
32. Illuminate\Database\QueryException formatMessage | |
…/vendor/laravel/framework/src/Illuminate/Database/QueryException.php35 | |
31. Illuminate\Database\QueryException __construct | |
…/vendor/laravel/framework/src/Illuminate/Database/Connection.php539 | |
30. Illuminate\Database\Connection run | |
…/vendor/laravel/framework/src/Illuminate/Database/Connection.php338 | |
29. Illuminate\Database\Connection statement | |
…/vendor/laravel/framework/src/Illuminate/Database/Connection.php295 | |
28. Illuminate\Database\Connection insert | |
…/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php30 | |
27. Illuminate\Database\Query\Processors\Processor processInsertGetId | |
…/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php1642 | |
26. Illuminate\Database\Query\Builder insertGetId | |
<#unknown>0 | |
25. call_user_func_array | |
…/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php872 | |
24. Illuminate\Database\Eloquent\Builder __call | |
…/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php1407 | |
23. Illuminate\Database\Eloquent\Builder insertGetId | |
…/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php1407 | |
22. Illuminate\Database\Eloquent\Model insertAndSetId | |
…/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php1377 | |
21. Illuminate\Database\Eloquent\Model performInsert | |
…/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php1288 | |
20. Illuminate\Database\Eloquent\Model save | |
…/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php400 | |
19. Illuminate\Database\Eloquent\Model create | |
…/app/controllers/PostsController.php51 | |
18. PostsController store | |
<#unknown>0 | |
17. call_user_func_array | |
…/vendor/laravel/framework/src/Illuminate/Routing/Controller.php194 | |
16. Illuminate\Routing\Controller callAction | |
…/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php93 | |
15. Illuminate\Routing\ControllerDispatcher call | |
…/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php62 | |
14. Illuminate\Routing\ControllerDispatcher dispatch | |
…/vendor/laravel/framework/src/Illuminate/Routing/Router.php905 | |
13. Illuminate\Routing\Router Illuminate\Routing\{closure} | |
<#unknown>0 | |
12. call_user_func_array | |
…/vendor/laravel/framework/src/Illuminate/Routing/Route.php105 | |
11. Illuminate\Routing\Route run | |
…/vendor/laravel/framework/src/Illuminate/Routing/Router.php969 | |
10. Illuminate\Routing\Router dispatchToRoute | |
…/vendor/laravel/framework/src/Illuminate/Routing/Router.php939 | |
9. Illuminate\Routing\Router dispatch | |
…/vendor/laravel/framework/src/Illuminate/Foundation/Application.php716 | |
8. Illuminate\Foundation\Application dispatch | |
…/vendor/laravel/framework/src/Illuminate/Foundation/Application.php691 | |
7. Illuminate\Foundation\Application handle | |
…/vendor/laravel/framework/src/Illuminate/Http/FrameGuard.php38 | |
6. Illuminate\Http\FrameGuard handle | |
…/vendor/laravel/framework/src/Illuminate/Session/Middleware.php60 | |
5. Illuminate\Session\Middleware handle | |
…/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php47 | |
4. Illuminate\Cookie\Queue handle | |
…/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php51 | |
3. Illuminate\Cookie\Guard handle | |
…/vendor/stack/builder/src/Stack/StackedHttpKernel.php23 | |
2. Stack\StackedHttpKernel handle | |
…/vendor/laravel/framework/src/Illuminate/Foundation/Application.php591 | |
1. Illuminate\Foundation\Application run | |
…/public/index.php49 | |
0. require_once | |
…/server.php19 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment