1,580 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 Laravel Hierarchy Users
So the desired reslt is something like
?
Replied to FFMpeg Executable Not Found
What is the output of which ffprobe
?
When I run that command I see
/usr/bin/ffprobe
Awarded Best Reply on Retrieving Unique Row With Summed Quantity
Something along the lines of
SELECT product_id, variant_id, sum(item_qty)
FROM subscriptions
GROUP BY product_id, variant_id
?
Replied to Retrieving Unique Row With Summed Quantity
Something along the lines of
SELECT product_id, variant_id, sum(item_qty)
FROM subscriptions
GROUP BY product_id, variant_id
?
Awarded Best Reply on Adding Second Form Action With Button It Does Not Work
What is the button supposed to do?
If it's not to submit a from you need to add some javascript function to it.
Replied to Adding Second Form Action With Button It Does Not Work
What is the button supposed to do?
If it's not to submit a from you need to add some javascript function to it.
Replied to CSS Overlap
I suggest you use a prefix on one of them. Bootstrap might become bs
. So to use it you do bs-row
instead of just row
.
https://stackoverflow.com/questions/29003264/customize-twitter-bootstrap-classnames
Replied to CSS Overlap
Not sure exactly what you mean but let's say you have a element with two classes
<style>
.boxed {
border: 1px solid black;
border-radius: 5px;
}
.rounded {
$border-radius: 10px;
}
</style>
<p class="boxed rounded">
The above <p>
would get rounded 10px corners.
If you change the order of the classes on the element.
<p class="rounded boxed">
It would get the 5px rounded corners.
You can use the !important
keyword to override the default cascade.
.boxed {
border: 1px solid black;
border-radius: 5px !important;
}
That would make the above example use rounded 5px corners. This is a bad practice.
If you have the same class name in several of those files it will give you strange effects since they will all be added.
Replied to Using External API To Create Record Directly But DRY Way
I would probably use the same controller for both the "html" and the "api" way since they are the same.
Something like
public function store(Request $request)
{
$movie = Movie::create($this->validate($request));
$message = $movie->title . ' Successfully added';
if($request->wantJson()) {
return response()->json([
'status => 200,
'message' => $message
]);
return redirect('/movies')->with(['message' => $message]);
}
Replied to How To Create Multi-pal Database Dynamically In Laravel
Something like
DB::getConnection()->statement('CREATE DATABASE :schema', array('schema' => $schemaName));
Should do the trick.
More info here https://laravel.io/forum/09-13-2014-create-new-database-and-tables-on-the-fly
Replied to Image And Video Processing Service
I'm guessing multi user setup?
Then you will need a dedicated host with lots of CPU, lots of memory, lots of diskspace and unlimited traffic. That is not cheap at all.
Replied to Weird Problem With Functions From Another Site
It should tell you on what row in your code it fails.
The code is barely readable so it's hard to understand what it does.
Replied to Multiple Tables
No.
Not until there is an actual insert into the table will the id be incremented and if a rollback occurs it will most likely just skip a number.
and so on.
Replied to Image And Video Processing Service
For images I'd use Intervention http://image.intervention.io/getting_started/installation#laravel
When it comes to video I'd use ffmpeg https://www.ffmpeg.org/
There is a laravel package for ffmpeg https://github.com/pascalbaljetmedia/laravel-ffmpeg
But like @fylzero says it's much easier to handle it on the local machine since it required lots of computing power to convert video.
You also need to be able to handle large uploads, lots of memory and a huge drive.
Replied to Passing Data From Database
I would create a service something like
Route::get('/someapi', '[email protected]');
public function someApi()
{
return SomeApi::all()->toJson()
}
async function fetchSomeApi() {
const response = await fetch('/someapi');
const json = await response.json();
document.querySelector('#somefield').value = json.somefield;
}
Replied to Install Php
When using XAMPP you don't need to install PHP seperatly. You just need to add the path to the php.exe file to your computers path.
https://docs.alfresco.com/4.2/tasks/fot-addpath.html
Then you need to close your commend window and open it again. After that youhould be good to go.
Replied to Unique Validation For Two Columns When Editing A Resource.
I would do a check to see if the values are the same for the fields then return with a message.
Both in the backend and the frontend.
something like
public function(Category $category, Request $request)
if($category->title == $request->title) {
return redirect->back()->withStatus('No changes made');
}
and
let isDirty = false;
document.querySelector('#title').addEvenListener('change', function() {
isDirty = true;
});
document.querySelector('#category_form').addEventListener('submit', function(event) {
if (isDirty) {
event.perventDefault();
console.log('No changes to save');
}
});
I haven't tested the code so there might be some type-Os.
Replied to Two Laravel Project Access Same Images Assets Publicly
Or use a common S3 bucket to store the images.
Replied to Laravel Works With Artisan Serve But Not With Vhost
Have you activated mod_rewrite in Wamp?
Replied to Advice Please
So you mean something like
That you have a form with let's say three fields
And instead of having names like
They have names like
And you get the labels from a table in the database.
The table has the following structure
The table is named scenrios or something like it
So in your controller you load a random scenario
$scenario = Scenerio::all()->random(1);
In your view you can then do something like
<label for="field1">{{ $scenario->field1 }}</label>
<input type="text" name="field1">
Replied to Eloquent Query To Filter Same Column Values
Not sure that is possible but give this a try
$filter = $request->filter
$products = DB::table('product_filters')
->selectRaw("product_id WHERE pf.filter_id in ?'
AND EXISTS (SELECT pfi.product_id
FROM product_filter pfi
WHERE pfi.product_id = pf.product_id
AND pfi.filter_id in ?", $filter, $filter)
->get();
Replied to Eloquent Query To Filter Same Column Values
So you only want product_id 42?
SELECT pf.product_id
FROM product_filter pf
WHERE pf.filter_id = 2
AND EXISTS (SELECT pfi.product_id
FROM product_filter pfi
WHERE pfi.product_id = pf.product_id
AND pfi.filter_id = 4);
Replied to Eloquent Query To Filter Same Column Values
Yes that query is fubar.
You want to get product filters that has the filter_id of 2 or 3.
In SQL I would do something like this
SELECT product_id
FROM product_filter
WHERE filter_id IN (2, 4);
In Eloquent the same query would look something like this
ProducFilter::whereIn('filter_id', [2, 4])->get();
And to make it more dynamic you just excehange the [2, 4]
with a variable passed into the request something like
public function(Request $request)
{
$filters = $request->filters;
$products = ProductFilter::whereIn('filter_id', $filters])->get():
}
You should of course validate the request->filters
before using it in your query
Replied to How Do I Get The Value From A Dropdown Menu To A Controller
In your case it should be $request->subject
Replied to It Is Possible Route A Url To Different Function?
You need to seperate the wildcards with a /
Route::get('{name}/{id}', [email protected]');
Be aware that it will catch any url in your app that has <something>/<something>
in it.
Use
Route::get('products/{id}', '[email protected]');
instead.
Or even better name the Controller and the method like so
Route::get('products/{id}', '[email protected]');
Replied to One To Many
You can name it whatever you like but I'd use the convetion for and name in comments
since it gets multiple comments and not just one.
That way your blade view gets more readable
Compare these two
@foreach($comment as $row)
{{ $row->body }}
@endforeach
or
@foreach($comments as $comment)
{{ $comment->body }}
@endforeach
I prefer the second one since I now know that we are working with comments and we do something for each comment. This might seem trivial in this case but if you have more fields you want to display it's easier to red without scrolling up to the beginning of the foreach to see what you are working with.
Replied to Tag In Detail Post Content
Yes and you should create a post_tags for the relation between them.
Replied to Combo Box
You need to change the $data2
to $data
in your foreach.
@foreach($data2 as $ctg)
<option value="{{ $ctg->id }}">{{ $ctg->ctg_name }}</option>
@endforeach
Replied to Combo Box
Dude you should know this by now...
Change
return view('admin.page.page')->with('list', $data);
to
return view('admin.page.page')->with(['list' => $data, 'data2' => $data2]);
I also highly suggest you change the variable names $data
and $data2
to something more descriptive.
The view code seems ok.
Replied to Tag In Detail Post Content
I suggest you use another database structure for this
You need three tables
You store each tag as a record in the tags table then you use the pivot table post_tags to link the post and tag. A classig many to many relationship.
https://laravel.com/docs/6.x/eloquent-relationships#many-to-many
Awarded Best Reply on Migrate
If you have a migration file named create_some_table
then Laravel is looking for a class named CreateSomeTable
so when you rename the file to create_some_other_table
you need to rename the class as well or Laravel will not find CreateSomeOtherTable
.
Replied to Migrate
If you have a migration file named create_some_table
then Laravel is looking for a class named CreateSomeTable
so when you rename the file to create_some_other_table
you need to rename the class as well or Laravel will not find CreateSomeOtherTable
.
Replied to My Variable Is Not Being Passed To My View
Or you can do this
return view('pages/pastpapers/igcse')->with([
'paper' =>$paper,
'pastpapers'=> $pastpapers,
'items' => $items,
'filter' => $filter
]);
Since you are mixing plural and sigular in your code make sure you have the same variable names in your view.
As I see it there are two ways to acheive this with as little headache as possible.
If we start with the first one you create a table that has the following fields
Then you can update the number of comments with your trigger.
The second we can create a view that on the fly calculates the number of comments
CREATE OR REPLACE VIEW comment_stats AS
SELECT c.id AS comment_id, count(*) AS number_of_comments
FROM comments
GROUP BY id
This is a bit over simplified when you add nesting. To solve that you need to add the "parent" to the view as well.
Replied to Slow Response After Clicking Add Button In Laravel
Do you have the proper indexes on offices
and students
?
From a quick run through it seems like you need to have indexes on
Replied to Intervention Image Problem
500 means that something went wrong.
If one image size works and not another it sounds to me that there might be a limitation of either the file size or the memory available for php.
Check these values in you php.ini
Replied to Auto Increment ID For Each Client Of The User
If you want to do something like that (which I advice against) you can do something like
Clients Table
and some client info fields.
Then you ignore the id and use the client_no instead as your counter.
That would mean you need to get the max client_no for that user every time you create a new client.
Something like
$clientNo = Client::where('user_id', Auth::user()->id)->count(); + 1;
Client::create([
'user_id' => Auth::user()->id,
'client_no' => $clientNo
]);
Replied to Handling Over 7k Records, GroupBy And Pagination
I would create a view that represents the data set and paginate from that.
CREATE OR REPLACE VIEW some_view AS
SELECT some_field, sum(some_other_field)
FROM some_table
GROUP BY some_field;
Then I can run a simple Eloquent query on it
$result = SomeView::paginate(25);
This example is very simplified.
You can use a migration to create the database view
In your up()
method
DB::statement("CREATE OR REPLACE VIEW some_view AS
SELECT some_field, sum(some_other_field)
FROM some_table
GROUP BY some_field");
Replied to How To Pass Parameter Value To 2 Different Functions In Same Controller?
You use parameters.
Function one calls function two with an argument.
Procedural way:
function one()
{
$foo = 'Some value';
two($foo);
}
function two($value)
{
store($value);
}
OOP way
public function one()
{
$foo = 'Some value';
$this->two($foo);
}
public function two($value)
{
store($value);
}
If you don't know how to pass arguments between functions in PHP I suggest you learn the basics of PHP before you start using Laravel.
Awarded Best Reply on Collections - Each Method
How do you populate the collection?
If it's from a table in the database it's much better to let the database handle the filtering.
Otherwise you can try forget
Replied to Collections - Each Method
How do you populate the collection?
If it's from a table in the database it's much better to let the database handle the filtering.
Otherwise you can try forget
Replied to Laravel Valet Broken After Upgrading To PHP 7.4
Did exactly that this weekend and took me about two hours to get it back up again.
Not sure what made it run again but I ran the following
brew uninstall [email protected]
brew uninstall nginx
brew uninstall dnsmasq
brew install php
brew install nginx
brew install dnsmasq
sudo valet install
Good luck.
Replied to Very High CPU Usage With Laravel-5.2
That is hard to predict but a proper stack uses less resources than xampp.
This document might shed some light.
https://www.dynatrace.com/news/blog/7-minute-workout-does-your-apache-web-server-need-love/
Replied to How To Get The Current With Previous Value Of An Array?
Not knowing exactly what you mean but something like this maybe?
@foreach($records as $record)
@if(! $loop->first())
{{ $records[$loop->index -1]->value }}
@endif
{{ $record->value}}
@if(! $loop->last())
{{ $records[$loop->index +1 ]->value }}
@endif
@endforeach
Replied to Very High CPU Usage With Laravel-5.2
@omkark610 I wouldn't use XAMPP in a production like environment since it's mostly for development. I suggest you set up a proper stack lemp or lamp.
https://www.howtoforge.com/perfect-server-debian-10-nginx-bind-dovecot-ispconfig-3.1/
https://www.howtoforge.com/perfect-server-debian-10-buster-apache-bind-dovecot-ispconfig-3-1/
Regardning the high CPU load it's probably due to the sql that is getting run. Without any code example it's hard to see the reason for it but it might be poorly written SQL and or missing indexes.
Take this simple query for example
SELECT * FROM some_table WHERE created_at BETWEEN '2019-12-01' AND'2019-12-02';
If you don't have an index on created_at
it will scan every record in your table.
When you add an index it will maybe read 10 records intead of thousands.
Oh and by the way, please don't hijack threads that are years old. Create a new one instead.