-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rating is somewhat functionning. Have to add policies so user can't vote more than once per recipe.
- Loading branch information
1 parent
ebb9e3d
commit 893baab
Showing
15 changed files
with
381 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Rating extends Model | ||
{ | ||
|
||
protected $table = 'ratings'; | ||
|
||
public $fillable = ['rating', 'rateable_id', 'user_id']; | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function rateable() | ||
{ | ||
return $this->morphTo(); | ||
} | ||
|
||
public function user() | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
|
||
|
||
public function recette() | ||
{ | ||
return $this->belongsTo(Recette::class); | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
<?php | ||
|
||
function randomRecipe() { | ||
|
||
$recette = App\Recette::inRandomOrder()->first(); | ||
|
||
return $recette; | ||
} |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
database/migrations/2020_02_28_162642_create_ratings_table.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
|
||
class CreateRatingsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('ratings', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->timestamps(); | ||
$table->integer('rating'); | ||
$table->morphs('rateable'); | ||
$table->bigInteger('user_id')->unsigned(); | ||
$table->index('rateable_id'); | ||
$table->index('rateable_type'); | ||
$table->foreign('user_id')->references('id')->on('users'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down() | ||
{ | ||
Schema::drop('ratings'); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
<template> | ||
<form class="form-horizontal recettestars" action="{{route('recetteStar', $recette->id)}}" :id="addStar" method="POST" style="display: inline-block;"> | ||
{{ csrf_field() }} | ||
<div class="form-group required"> | ||
<div class="col-sm-12"> | ||
<input class="star star-5" value="5" id="star-5" type="radio" name="star"/> | ||
<label class="star star-5" for="star-5"></label> | ||
<input class="star star-4" value="4" id="star-4" type="radio" name="star"/> | ||
<label class="star star-4" for="star-4"></label> | ||
<input class="star star-3" value="3" id="star-3" type="radio" name="star"/> | ||
<label class="star star-3" for="star-3"></label> | ||
<input class="star star-2" value="2" id="star-2" type="radio" name="star"/> | ||
<label class="star star-2" for="star-2"></label> | ||
<input class="star star-1" value="1" id="star-1" type="radio" name="star"/> | ||
<label class="star star-1" for="star-1"></label> | ||
</div> | ||
</div> | ||
</form> | ||
</template> | ||
|
||
|
||
<script> | ||
$('#addStar').change('.star', function(e) { | ||
$(this).submit(); | ||
}); | ||
</script> |
Oops, something went wrong.