Created
July 24, 2015 11:59
-
-
Save mdunbavan/952ded2f60cfbf1a79c4 to your computer and use it in GitHub Desktop.
Laravel updates
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 | |
@extends('app') | |
@section('content') | |
<article class="container"> | |
<h2>Edit Offer</h2> | |
{!! Form::model($offer, ['route' => ['offers.update', $offer], 'method' => 'PATCH', 'files' => true]) !!} | |
@include('offers/partials/_form', ['submit_text' => 'Edit Offer']) | |
{!! Form::close() !!} | |
</article> | |
@endsection |
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 | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
class Offer extends Model | |
{ | |
/** | |
* The database table used by the model. | |
* | |
* @var string | |
*/ | |
protected $table = 'offers'; | |
/** | |
* The attributes that are mass assignable. | |
* | |
* @var array | |
*/ | |
protected $fillable = ['name', 'address', 'image', 'description', 'offer_headline','offer_subheader','offer_terms','map_location','phone_number','website']; | |
public static $rules = array( | |
'name' => 'required|max:255|unique:offers', | |
'address' => 'required|max:255', | |
'description' => 'required', | |
'offer_terms' => 'required', | |
'map_location' => 'required', | |
'phone_number' => 'required', | |
'image' => 'image|mimes:jpeg,jpg,png,bmp,gif,svg' | |
); | |
} |
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 edit(Offer $offer, $id) | |
{ | |
// | |
$this->middleware('auth'); | |
$offer = Offer::findOrFail($id); | |
return view('offers.edit', compact('offer')); | |
} | |
/** | |
* Update the specified resource in storage. | |
* | |
* @param Request $request | |
* @param int $id | |
* @return Response | |
*/ | |
public function update($id, Offer $offer) | |
{ | |
//array('keys', 'to', 'remove') | |
$input = array_except(Input::all(), array('_token','_method') ); | |
//$input = Request::except('_method','_token','image'); | |
$offer->update($input); | |
//dd($input); | |
return Redirect::route('offers.show',$offer->id)->with('message', 'Offer updated.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment