Member Since 5 Years Ago
1,040 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.
Earned once your experience points ranks in the top 10 of all Laracasts users.
Started a new Conversation Uncaught ReferenceError: $ Is Not Defined
I have new Laravel 8 instalation and a little problem with js code. In js/bootstrap.js I have a code:
window.$ = require('jquery');
window._ = require('lodash');
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
alert(window.$);
import './bootstrap';
import './components/alert';
webpack.mix.js creates the public/app.js file. But console throws me an error from components/alert.js which tries to use $ as jQuery. Also alert(window.$) does not run. Can somebody tell me what is wrong? Thanks.
Replied to Why Do All Generated Files Use Spaces For Indentation?
Spaces? The world is in the power of evil...
Replied to Laravel + Docker + Windows
Here is detailed explanation of my problem https://superuser.com/questions/1619358/windows-docker-wsl2/1619363#1619363
Replied to Laravel + Docker + Windows
Also the Sail runs as docker containers -> After Sail has been installed, you may run the sail:install Artisan command. This command will publish Sail's docker-compose.yml file to the root of your application:
Started a new Conversation Laravel + Docker + Windows
I am starting with Docker. As I see Laravel has docker container for new installation. But one of the requirements is to install WSL2 with Docker. WSL2 for Windows means to join insiders program for Windows and it means:
The experimental and early prerelease software and services made available to you in the Program might not be tested. You might experience crashes, security vulnerabilities, data loss, or damage to your device. ...
Do you have experience with running Laravel docker container on Windows? I have a Docker without WSL2 and it works. But Docker has some warnings about shared files between host and container....
What do you mean about it?
Replied to Form Submit With @csrf Throws 419 Expired Error
It seems it was some kind of deploy problem.
Started a new Conversation Form Submit With @csrf Throws 419 Expired Error
Hi, I have a simple register form with @csrf field inside but I am getting an 419 expired error on production. On local server it works well. I dont understand. Can somebody tell me please what is going on? Thanks.
PS The weird thing is that validation works.
Awarded Best Reply on Why This Join Return 11000 Results
$m = Manufacturer::select('manufacturers.*')
->withTranslations( LanguageHelper::getLangId() )
->with('image')
->groupBy('manufacturers.id')
->join('manufacturer_product', 'manufacturers.id', '=', 'manufacturer_product.manufacturer_id')
->join('category_product', function($join) {
$join->on('category_product.product_id', '=', 'manufacturer_product.product_id')
->where('category_product.category_id', '=', $this->id);
})->get();
groupBy() am I right?
Replied to Why This Join Return 11000 Results
Yes I saw it in debug bar. Is the groupBy the solution or is there a better way?
Replied to Why This Join Return 11000 Results
$m = Manufacturer::select('manufacturers.*')
->withTranslations( LanguageHelper::getLangId() )
->with('image')
->groupBy('manufacturers.id')
->join('manufacturer_product', 'manufacturers.id', '=', 'manufacturer_product.manufacturer_id')
->join('category_product', function($join) {
$join->on('category_product.product_id', '=', 'manufacturer_product.product_id')
->where('category_product.category_id', '=', $this->id);
})->get();
groupBy() am I right?
Started a new Conversation Why This Join Return 11000 Results
Hi, can somebody tell me please what is wrong with this join request to Manufacturer entity?
$m = Manufacturer::select('manufacturers.*')
->withTranslations( LanguageHelper::getLangId() )
->with('image')
->join('manufacturer_product', 'manufacturers.id', '=', 'manufacturer_product.manufacturer_id')
->join('category_product', function($join) {
$join->on('category_product.product_id', '=', 'manufacturer_product.product_id')
->where('category_product.category_id', '=', $this->id);
})->get();
Log::debug($m->count());
DB tables: manufactures: id manufacturer_product: manufacturer_id, product_id product_category: product_id, category_id
The real count of manufacturers is 29. But the result count is 11000. I need to get all manufacturers which are joined via manufacturers_products to category.id. I dont want all relations but the unique entities. How to do it in Laravel?
Replied to Collection Map()
Not really. Try to change numbers to objects and then original collection will be modified.
Replied to Collection Map()
My bad, I forgot return in lambda. But the problem was and it really modifies original collection that if there are objects in collection they are modified.
Replied to Database + Eloquent Model Best Practice
I though you mean DB joins. so now I am here with this stupid question.
Replied to Database + Eloquent Model Best Practice
Why you did not mention this way yesterday in this discussion https://laracasts.com/discuss/channels/general-discussion/sql-exists-query-does-not-return-relevant-result ?
Replied to Database + Eloquent Model Best Practice
I did not see the join for Eloquent in documentation. Where is it?
Replied to Collection Map()
No I still dont understand. I forgot to return from lambda. But items in collection are affected.
Replied to Collection Map()
Ah I see it now. The collection is not modified but objects in there are.
Replied to Collection Map()
Yes you are right but this works. The original collection contains new field slug. So how is it possible cause I test it against $products typeof Collection and it is true.
Started a new Conversation Database + Eloquent Model Best Practice
Hi, I have a code which works well but I would like to know what is the best practice to do it. If the way in the code is ok or if it is overkill to call eloquent whereIn() and then build Eloquent entities and call paginate():
$productsIds = DB::table('products')
->join('category_product', 'products.id', '=', 'category_product.product_id')
->join('categories', 'categories.id', '=', 'category_product.category_id')
->where('categories.slug', '=', 'tlaciarne')
->where('products.name', 'like', "$value")
->select('products.id')
->get()
->pluck('id');
$products = Product::whereIn('id', $productsIds)
->withTranslations(LanguageHelper::getLangId())
->with('manufacturers')
->with('image')
->latest()
->paginate(20);
Replied to Collection Map()
This is my code:
$products = DB::table('products')
->leftJoin('products_texts', 'products.id', '=', 'products_texts.product_id')
->leftJoin('files', 'products.image_id', '=', 'files.id')
->select('products.name', 'files.name as url', 'products_texts.name as t_name')
->where('products_texts.name', 'like', "%$value%")
->limit(10)
->get();
$products->map(function ($item, $key) {
$item->slug = Product::slugify($item->name);
});
Started a new Conversation Collection Map()
Hi, a documentation https://laravel.com/docs/8.x/collections#method-map about collections says the map() method does not modify original collection and to do this we should use transform() method. But is seems it is not true in v 8.0. Map() modifies original collection and returns damaged collection where all items are null. So what is going on there?
Replied to SQL Exists Query Does Not Return Relevant Result
One question. What should be the right way to make this query? Can I make a DB inner join get products ids and then call
Product::whereIn('id', $ids);
with necessary relations? Is it ok or not?
Replied to SQL Exists Query Does Not Return Relevant Result
What the hell is it? It is about 50 000 model on homepage.
Replied to SQL Exists Query Does Not Return Relevant Result
Ok so how many model retrieved from what?
Replied to SQL Exists Query Does Not Return Relevant Result
How to enable models tab in debugbar? First time I hear about models tab.
Replied to SQL Exists Query Does Not Return Relevant Result
But then I lost the Eloquent relations as objects .... I would like to avoid it.
Replied to SQL Exists Query Does Not Return Relevant Result
This should not be the problem cause table is in utf8_slovak_ci collation it means it is case insensitive. Also this command throws an error unknow column LOWER(name)
Started a new Conversation SQL Exists Query Does Not Return Relevant Result
I have a Laravel application with this Eloquent query:
$products = Product::where('name', 'LIKE', "%{$value}%")
->whereHas('categories', function($q) {
$q->where( 'slug', 'tonery-cartridge' );
})->with('manufacturer')
->with('sm_image')
->orderBy('created_at','DESC')
->take(10)
->get();
This code generates the sql command like:
select * from `products` where `name` LIKE '%can%'
and exists (
select * from `categories` inner join `category_product`
on `categories`.`id` = `category_product`.`category_id`
where `products`.`id` = `category_product`.`product_id`
and `slug` = 'tonery-cartridge'
)
order by `created_at` desc limit 10
I am sure there are products which name contains "can" string and which belongs to category with slug "tonery-cartridge". Why this query returns empty result? If I try to make inner join sql manually it works well as you can see on the screenshot here: https://stackoverflow.com/questions/65080957/sql-exists-query-does-not-return-relevant-result?noredirect=1#comment115057625_65080957
Replied to $kernel->handle(...) Takes Too Much Time
I forgot to write that problem is fixed. It was a bad sql query.
Awarded Best Reply on Route Type Hint Resolves Wrong
Ok I Have it. There is a definition in RouteServiceProvider::boot() for this parameter name.
Replied to Route Type Hint Resolves Wrong
Ok I Have it. There is a definition in RouteServiceProvider::boot() for this parameter name.
Started a new Conversation Route Type Hint Resolves Wrong
Hi, I have a controller with method expecting two parameters. First one $manufacturer is type hinted but second one $categroy should be raw string.
class BrandController extends Controller
{
public function show(Brand $brand, $category)
{
...
}
}
The route for this controllet looks like:
Route::get('/brand/{brand}/{category}', '[email protected]')->name('brand.show');
This results in 404 not found cause application tries to inject TransCategory model to the second parameter. I dont understand why this happend if parameter $category is not type hinted. What is going on at the background?
Started a new Conversation $kernel->handle(...) Takes Too Much Time
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
I have a problem with long application loading. The problem seems to be in the code above in index.php. Can anybody tell me where could be the problem?
Replied to Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' Not Found
I needed to reinstall it and now it works. Someone did dirty remove of this library and it stop working. Now it is ok. Thanks.
Started a new Conversation Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' Not Found
Hi, I need to install IdeHelperServiceProvider but I am getting error Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' not found from composer dum-autoload. Also php artisan does not show ide helper command although I have it in composer and I can see it in vendor directory. What am I doing wrong?
Started a new Conversation Swift_RfcComplianceException Address In Mailbox Given [] Does Not Comply With RFC 2822, 3.6.2.
I have a simple code to send two emails.
dd(trim($email), trim(config('mail.from.address')));
Mail::to(trim(config('mail.from.address')))->send(new OrderStatusForm($this,$status,$attachment, false));
Mail::to(trim($email))->send(new OrderStatusForm($this,$status,$attachment, true));
Both email addresses in dd() are valid. But both lines with Mail::to() throw me an error Swift_RfcComplianceException Address in mailbox given [] does not comply with RFC 2822, 3.6.2. I dont understand. What is wrong with that?
Replied to Base Table Not Found During Composer Install
Ok but what if I need to run this code e.g. as cron which sends an emails? This line for views is not the only reason of this error. There are also something like
$settings = GlobalSettings::all();
...
Config::set('mail', $config);
which wants to set config variables...
Replied to Base Table Not Found During Composer Install
As I found out it triggers AppServiceProvider::boot() method (dont understand why on composer install...) and there is a line
view()->share('currency', app('activeCurrency')->symbol);
How can I remove it from boot() or where to store this call properly?
Replied to Base Table Not Found During Composer Install
Any progress in this issue? I have the same problem. SQL triggers while composer install. I dont understand why.
Replied to Instagram For Laravel
What it means? Whole Instagram is deprecated or whole api is deprecated? Here I dont se anything about it https://developers.facebook.com/docs/instagram-basic-display-api/getting-started
Started a new Conversation Instagram For Laravel
Hi there I need to choose best package for instagram api implementation. Can you give me a hint? The best package I found is abandoned. Other packages can to compare to it.
Thnak you.
Replied to Migration Does Not Change Column Name
Cause much more interesting is that Laravel migration does not allow this operations. Its really weird and I need to understand things. Its is my nature. There is no reason to throw errors on this....