Reputation: 1732
I logged in to my heroku app which is a hotel review app: http://immense-beach-76879.herokuapp.com/. Apparently, it won't display the data I entered at http://immense-beach-76879.herokuapp.com/reviews. It was only showing the error. It said something about the integer being the wrong choice to use since "kiki" is supposed to be a string, correct? If you need to look at my code, here it is: https://github.com/kikidesignnet/hotelreviews.
Here is my error:
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "kiki" (SQL: select * from "reviews" where "user_id" in (1, kiki, [email protected], ?, 2020-02-07 05:57:47, 2020-02-07 05:57:47) order by "created_at" desc limit 20)
I've been following this tutorial to learn about Laravel and how React/Laravel works together: https://kaloraat.com/articles/laravel-react-crud-tutorial and their github repo:https://github.com/kaloraat/laravel-react-crud
Here is my migrating create_reviews_table.php
:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateReviewsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('reviews', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned()->index();
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('reviews');
}
}
As you can see, this app was supposed to register a new user. Then when the user log in and submit a review of the hotel, the reviews.api was supposed to save the data in and display the reviews underneath the review form.
All I can see is that the form is working, submitting the data underneath but it's not showing any dada...
Upvotes: 0
Views: 6402
Reputation: 4813
You may change this line (17) in your index
method inside App\Http\Controllers\ReviewController
$allReviews = $review->whereIn('user_id', $request->user())->with('user');
To
$allReviews = $review->where('user_id', $request->user()->id)->with('user');
Or
$allReviews = $review->where('user_id', \Auth::id())->with('user');
Upvotes: 1