Skip to content

Commit

Permalink
feat(frontend): Work on Recette controller
Browse files Browse the repository at this point in the history
User can now add Recipe.
  • Loading branch information
scouillard committed Feb 11, 2020
1 parent cb32598 commit 451e63a
Show file tree
Hide file tree
Showing 24 changed files with 11,049 additions and 51 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class HomeController extends Controller
*/
public function __construct()
{
$this->middleware('auth');
// $this->middleware('auth');
}

/**
Expand Down
21 changes: 21 additions & 0 deletions app/Http/Controllers/ProfilesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;


class ProfilesController extends Controller
{
public function index($user)
{

$user = User::find($user);


return view('home', [
'user' => $user,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
use App\Recette;
use Illuminate\Http\Request;

class RecetteController extends Controller
class RecettesController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/

public function __construct() {
$this->middleware('auth');
}


public function index()
{
//

}

/**
Expand All @@ -24,7 +30,7 @@ public function index()
*/
public function create()
{
//
return view('recettes/create');
}

/**
Expand All @@ -35,7 +41,26 @@ public function create()
*/
public function store(Request $request)
{
//

$data = request()->validate([
'name' => 'required',
'description' => 'required',
'ingredient' => 'required',
'instruction' => 'required',
'image' => ['required', 'image'],
]);

$imagePath = request('image')->store('uploads', 'public');

auth()->user()->recettes()->create([
'name' => $data['name'],
'description' => $data['description'],
'ingredient' => $data['ingredient'],
'instruction' => $data['instruction'],
'image' => $imagePath,
]);

return redirect('/profile/' . auth()->user()->id);
}

/**
Expand All @@ -44,9 +69,9 @@ public function store(Request $request)
* @param \App\Recette $recette
* @return \Illuminate\Http\Response
*/
public function show(Recette $recette)
public function show(\App\Recette $recette)
{
//
return view('recettes/show', compact('recette'));
}

/**
Expand Down
14 changes: 14 additions & 0 deletions app/Profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Profile extends Model
{

public function profile() {
return $this->belongsTo(User::class);
}

}
11 changes: 8 additions & 3 deletions app/Recette.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

use Illuminate\Database\Eloquent\Model;

class Recette extends Model
{
//
class Recette extends Model {

protected $guarded = [];

public function user() {
return $this->belongsTo(User::class);
}

}
9 changes: 9 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,13 @@ class User extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];

public function recettes() {
return $this->hasMany(Recette::class)->orderBy('created_at', 'DESC');
}

public function profile() {
return $this->hasOne(Profile::class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ public function up()
Schema::create('recettes', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
$table->unsignedBigInteger('user_id');
$table->string('name')->nullable();
$table->text('description')->nullable();
$table->string('image')->nullable();
$table->string('ingredient')->nullable();
$table->string('instruction')->nullable();
$table->float('rating')->nullable();
$table->index('user_id');
});
}

Expand Down
34 changes: 34 additions & 0 deletions database/migrations/2020_02_11_005246_create_profiles_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

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

class CreateProfilesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('profiles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();

$table->unsignedBigInteger('user_id');
$table->index('user_id');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('profiles');
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"@fortawesome/fontawesome-free": "^5.12.1",
"axios": "^0.19",
"bootstrap": "^4.1.0",
"cross-env": "^5.1",
Expand Down
Loading

0 comments on commit 451e63a

Please sign in to comment.