Member Since 8 Months Ago
3,640 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
Replied to How To Upload Images With Froala Editor?
Did you make this work? I just resolved this yesterday and upload image is working fine on Froala
Awarded Best Reply on Array_merge(): Expected Parameter 1 To Be An Array, String Given
Solved. The return view was missing compact(): return view ('2ndscreen', compact('question');
Replied to Array_merge(): Expected Parameter 1 To Be An Array, String Given
Solved. The return view was missing compact(): return view ('2ndscreen', compact('question');
Started a new Conversation Array_merge(): Expected Parameter 1 To Be An Array, String Given
I have the following code:
public function selected_degree ($degree_id) {
session(['degree_id' => $degree_id]);
$question = DB::table('questions')
->select('questions.question_text','questions.answer_time_minutes','questions.answer_time_seconds', 'question_id')
->where('degree_id', session('degree_id'))
->orderByRaw('RAND()')
->take(1)->first();
// save the question id returned in an array in session
Session::push('questions', $question->question_id);
// save the position as 0 because is the first time the query is run
Session::put('array_position', 0);
return view('2ndscreen', 'question');
}
I don't understand why I am getting this error: array_merge(): Expected parameter 1 to be an array, string given.
There are no more details about this error.
Started a new Conversation Array Player
I was wondering to know which ways I have to go through an array through previos/next buttons, starting from the latest position of an array.
Replied to Passing A Parameter Through URL
Finally I was able to resolve this. Laravel was showing $degree_id value as '?' when I was using dd(DB::getQueryLog());
However, this value was passed but not displayed using this function. I thought the query was wrong (displaying ? instead of a number) but it worked anyway.
Replied to Passing A Parameter Through URL
I'm passing the degree_id through the URL but the query doesn't insert the value. Instead, it returns ?
dd($degree_id') returns 1 The query should return where questions.degree_id = 1 ->where('questions.degree_id', $degree_id)
However, the complete query using dd(DB::getQueryLog()); returns:
select questions
.question_text
, questions
.answer_time_minutes
, questions
.answer_time_seconds
from questions
inner join universities
on universities
.university_id
= questions
.university_id
where questions
.degree_id
= ? order by RAND() limit 1
As you can see, the query returns = ? but it should return = 1
Replied to Passing A Parameter Through URL
Good suggestion. It has value 1 so it's working but
->where('questions.degree_id', $degree_id)
is returning
where questions
.degree_id
= ?
I'm not sure why
Started a new Conversation Passing A Parameter Through URL
Route::get('/questions/{category}', '[email protected]')->name('welcomesecond');
executes the following:
public function second($degree_id) {
$question = DB::table('questions')
->select('questions.question_text','questions.answer_time_minutes','questions.answer_time_seconds')
->join('universities', 'universities.university_id', 'questions.university_id')
->orderByRaw('RAND()')
->where('questions.degree_id', $degree_id)
->take(1)->first();
return view('2ndscreen', compact('question'));
}
However, even when I pass the value through the URL, $degree_id has no value assigned: URL: questions/1
Any ideas what I am doing wrong?
Replied to Can't See The Complete Query So I Don't Know What's Wrong
The 2nd returns Trying to get property 'question_text' of non-object
The 1st one returns the query :)
Replied to Can't See The Complete Query So I Don't Know What's Wrong
the query logs returns an empty array:
[]
$question = DB::table('questions')
->select('questions.question_text','questions.answer_time_minutes','questions.answer_time_seconds')
->join('universities', 'universities.university_id', 'questions.university_id')
->orderByRaw('RAND()')
->where('questions.degree_id', $degree_id)
->take(1)->first();
DB::enableQueryLog();
dd(DB::getQueryLog());
Replied to Can't See The Complete Query So I Don't Know What's Wrong
I just inserted it at the end:
$question = DB::table('questions')
->select('questions.question_text','questions.answer_time_minutes','questions.answer_time_seconds')
->join('universities', 'universities.university_id', 'questions.university_id')
->orderByRaw('RAND()')
->where('questions.degree_id', $degree_id)
->take(1)->first()
->toSql ();
Replied to Can't See The Complete Query So I Don't Know What's Wrong
->toSql (); returns Call to a member function toSql() on null
Started a new Conversation Can't See The Complete Query So I Don't Know What's Wrong
I have the following function: public function second($degree_id) {
$question = DB::table('questions')
->select('questions.question_text','questions.answer_time_minutes','questions.answer_time_seconds')
->join('universities', 'universities.university_id', 'questions.university_id')
->orderByRaw('RAND()')
->where('questions.degree_id', $degree_id)
->take(1)->first();
return view('2ndscreen', compact('question'));
}
This query it is supposed to:
Is there any way to see this query in raw format so I can find out what's wrong?
Thank you
Replied to How To Reload A Foreach Or View?
but a new random question must be loaded from the database so I must load the index function again. Javascript and AJAX won't be able to send and receive data from the controller
Started a new Conversation How To Reload A Foreach Or View?
I have a controller which loads a random question:
public function index () {
$question = Question::orderByRaw('RAND()')->take(1)->get();
return view('welcome', compact('question'));
}
Inside the view, there is a foreach which displays the random question:
<div class="block-content">
@foreach($question as $q)
<h2 class="font-w400">{{$q->question_text}}</h2>@endforeach</div>
So, I want to insert a button on the view to get a new random question without having to reload the page (because in the future I want to add some filters through Radiobuttons and such so send certain parameters to the controller and get random questions based on certain criteria).
Now you know the situation, which is the best approach? Should I create a secondary view to load the foreach as a section and then reload the section only?
Commented on Databases And Migrations
Where do you change varchar to 150? I can't find the type of column on migrations folder