Skip to content

Commit

Permalink
Merge pull request #5 from malinink/master
Browse files Browse the repository at this point in the history
hal
  • Loading branch information
Iren committed Nov 8, 2015
2 parents b608f8b + 55b5f03 commit 07b83c0
Show file tree
Hide file tree
Showing 31 changed files with 428 additions and 56 deletions.
2 changes: 1 addition & 1 deletion app/Fruit.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ class Fruit extends Model
{
protected $table = 'fruits';

protected $fillable = ['identity', 'name', 'color', 'weight'];
protected $fillable = ['identity', 'name', 'color', 'weight', 'price', 'condition'];
}
8 changes: 6 additions & 2 deletions app/Http/Controllers/Fruits.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public function create()

public function store()
{
$request = Request::only('identity', 'name', 'color', 'weight');
$request = Request::only('identity', 'name', 'color', 'weight', 'price', 'condition');
$fruit = new Fruit();
$fruit->identity = $request['identity'];
$fruit->name = $request['name'];
$fruit->color = $request['color'];
$fruit->weight = $request['weight'];
$fruit->price = $request['price'];
$fruit->condition = $request['condition'];
$fruit->save();

return redirect('fruits')->with('message', 'Fruit created successfully!');
Expand All @@ -48,12 +50,14 @@ public function edit($id)

public function update($id)
{
$new = Request::only('identity', 'name', 'color', 'weight');
$new = Request::only('identity', 'name', 'color', 'weight', 'price', 'condition');
$fruit = Fruit::find($id);
$fruit->identity = $new['identity'];
$fruit->name = $new['name'];
$fruit->color = $new['color'];
$fruit->weight = $new['weight'];
$fruit->price = $new['price'];
$fruit->condition = $new['condition'];
$fruit->save();

return redirect('fruits')->with('message', 'Fruit updated!');
Expand Down
49 changes: 43 additions & 6 deletions app/Http/Controllers/RickastleyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Rickastley;
use Illuminate\Http\Request;

use App\Http\Requests;
Expand All @@ -16,7 +17,11 @@ class RickastleyController extends Controller
*/
public function index()
{
return view('rickastley.index');
$rickastley = Rickastley::all();

return view('rickastley.index', [
'rickastley' => $rickastley
]);
}

/**
Expand All @@ -37,7 +42,20 @@ public function create()
*/
public function store(Request $request)
{
return view('rickastley.store');
$identity = $request->input('identity');
$firstname = $request->input('firstname');
$lastname = $request->input('lastname');
$rate = $request->input('rate');

$new = Rickastley::create([
'identity' => $identity,
'firstname' => $firstname,
'lastname' => $lastname,
'rate' => $rate
]);
$new->save();

return redirect()->route('rickastley.index');
}

/**
Expand All @@ -48,7 +66,10 @@ public function store(Request $request)
*/
public function show($id)
{
return view('rickastley.show');
$rick = Rickastley::find($id);
return view('rickastley.show', [
'rick' => $rick
]);
}

/**
Expand All @@ -59,7 +80,10 @@ public function show($id)
*/
public function edit($id)
{
return view('rickastley.edit');
$rick = Rickastley::find($id);
return view('rickastley.edit', [
'rick' => $rick
]);
}

/**
Expand All @@ -71,7 +95,19 @@ public function edit($id)
*/
public function update(Request $request, $id)
{
return view('rickastley.update');
$identity = $request->input('identity');
$firstname = $request->input('firstname');
$lastname = $request->input('lastname');
$rate = $request->input('rate');

$obj = Rickastley::find($id);
$obj->identity = $identity;
$obj->firstname = $firstname;
$obj->lastname = $lastname;
$obj->rate = $rate;
$obj->save();

return redirect()->route('rickastley.index');
}

/**
Expand All @@ -82,6 +118,7 @@ public function update(Request $request, $id)
*/
public function destroy($id)
{
return view('rickastley.destroy');
Rickastley::destroy($id);
return redirect()->route('rickastley.index');
}
}
43 changes: 43 additions & 0 deletions app/Http/Controllers/Sports.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Routing\Controller as BaseController;

class Sports extends BaseController
{
public function index()
{
return view('sports.index');
}

public function create()
{
return view('sports.create');
}

public function store()
{
return view('sports.store');
}

public function show($id)
{
return view('sports.show', compact('id'));
}

public function edit($id)
{
return view('sports.edit', compact('id'));
}

public function update($id)
{
return view('sports.update', compact('id'));
}

public function destroy($id)
{
return view('sports.destroy', compact('id'));
}
}
33 changes: 32 additions & 1 deletion app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,37 @@
Route::post('computers/{id}','ComputersController@update');
Route::delete('computers/{id}', 'ComputersController@destroy');


Route::get('sports/',[
'uses' => 'Sports@index',
'as' => 'sports.index'
]);
Route::get('sports/create',[
'uses' => 'Sports@create',
'as' => 'sports.create'
]);
Route::get('sports/{id}/edit',[
'uses' => 'Sports@edit',
'as' => 'sports.edit'
]);
Route::get('sports/{id}',[
'uses' => 'Sports@show',
'as' => 'sports.show'
]);
Route::delete('sports/{id}',[
'uses' => 'Sports@destroy',
'as' => 'sports.destroy'
]);
Route::put('sports/{id}',[
'uses' => 'Sports@update',
'as' => 'sports.update'
]);
Route::post('sports/',[
'uses' => 'Sports@store',
'as' => 'sports.store'
]);


Route::get('/cars', [
'as' => 'index',
'uses' => 'CarsController@index'
Expand Down Expand Up @@ -157,7 +188,7 @@
'as' => 'rickastley.update', 'uses' => 'RickastleyController@update'
]);
Route::delete('{id}', [
'as' => 'rickastley.delete', 'uses' => 'RickastleyController@delete'
'as' => 'rickastley.destroy', 'uses' => 'RickastleyController@destroy'
]);

});
Expand Down
12 changes: 12 additions & 0 deletions app/Rickastley.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Rickastley extends Model
{
public $timestamps = false;

protected $fillable = ['identity', 'firstname', 'lastname', 'rate'];
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public function up()

public function down()
{
Schema::drop('Countries');
Schema::drop('countries');
}
}
34 changes: 34 additions & 0 deletions database/migrations/2015_11_05_201806_create_rickastleys_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRickastleysTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('rickastleys', function (Blueprint $table) {
$table->increments('id');
$table->integer('identity');
$table->string('firstname');
$table->string('lastname');
$table->string('rate');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('rickastleys');
}
}
23 changes: 23 additions & 0 deletions database/migrations/2015_11_06_142423_add_fields_to_fruits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddFieldsToFruits extends Migration
{
public function up()
{
Schema::table('fruits', function ($table) {
$table->double('price', 15, 2);
$table->string('condition');
});
}

public function down()
{
Schema::table('fruits', function ($table) {
$table->dropColumn('price');
$table->dropColumn('condition');
});
}
}
16 changes: 0 additions & 16 deletions resources/views/Countries/Countries_show.blade.php

This file was deleted.

1 change: 1 addition & 0 deletions resources/views/countries/countriesCreate.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
{!! Form::submit('Create', ['class' => 'btn btn-default']) !!}
{!!Form::close()!!}
@stop

8 changes: 7 additions & 1 deletion resources/views/fruits/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
{!! Form::text('identity', null, ['class' => 'form-control']) !!}

{!! Form::label('Name') !!}
{!! Form::select('name', ['Apple' => 'Apple', 'Kiwi' => 'Kiwi'], null, ['class' => 'form-control']) !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}

{!! Form::label('Color') !!}
{!! Form::text('color', null, ['class' => 'form-control']) !!}

{!! Form::label('Weight') !!}
{!! Form::text('weight', null, ['class' => 'form-control']) !!}

{!! Form::label('Price') !!}
{!! Form::text('price', null, ['class' => 'form-control']) !!}

{!! Form::label('Condition') !!}
{!! Form::select('condition', ['Fresh' => 'Fresh', 'Rotten' => 'Rotten'], null, ['class' => 'form-control']) !!}

<br>
{!! Form::submit('Create', ['class' => 'btn btn-success']) !!}

Expand Down
7 changes: 6 additions & 1 deletion resources/views/fruits/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
{!! Form::text('identity', null, ['class' => 'form-control']) !!}

{!! Form::label('Name') !!}
{!! Form::select('name', ['Apple' => 'Apple', 'Kiwi' => 'Kiwi'], null, ['class' => 'form-control']) !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}

{!! Form::label('Color') !!}
{!! Form::text('color', null, ['class' => 'form-control']) !!}

{!! Form::label('Weight') !!}
{!! Form::text('weight', null, ['class' => 'form-control']) !!}

{!! Form::label('Price') !!}
{!! Form::text('price', null, ['class' => 'form-control']) !!}

{!! Form::label('Condition') !!}
{!! Form::select('condition', ['Fresh' => 'Fresh', 'Rotten' => 'Rotten'], null, ['class' => 'form-control']) !!}
<br>
{!! Form::submit('Update', ['class' => 'btn btn-primary']) !!}

Expand Down
4 changes: 4 additions & 0 deletions resources/views/fruits/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<th> Name </th>
<th> Color </th>
<th> Weight </th>
<th> Price </th>
<th> Condition </th>
<th> Control </th>
<th> </th>
</tr>
Expand All @@ -31,6 +33,8 @@
<td> {!! $fruit['name'] !!} </td>
<td> {!! $fruit['color'] !!} </td>
<td> {!! $fruit['weight'] !!} </td>
<td> {!! $fruit['price'] !!} </td>
<td> {!! $fruit['condition'] !!} </td>
<td> {!! link_to_action('Fruits@edit', 'edit', [$fruit['id']], ['class' => 'btn btn-default btn-sm']) !!} </td>
<td> {!! Form::open(['action' => ['Fruits@destroy', $fruit['id']], 'method'=>'DELETE']) !!}
{!! Form::submit('destroy', ['class' => 'btn btn-default btn-sm']) !!}
Expand Down
2 changes: 2 additions & 0 deletions resources/views/fruits/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
<h1>{!! $fruit['name'] !!}</h1>
<h1>{!! $fruit['color'] !!}</h1>
<h1>{!! $fruit['weight'] !!}</h1>
<h1>{!! $fruit['price'] !!}</h1>
<h1>{!! $fruit['condition'] !!}</h1>
{!! link_to_action('Fruits@index', 'Back to fruits', [], ['class' => 'btn btn-success']) !!}
@endsection
Loading

0 comments on commit 07b83c0

Please sign in to comment.