Member Since 2 Years Ago
4,600 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.
Replied to I Need To Get Related Table In Array Format By 'with', But Pluck Not Work
I found a solution :) this code work perfectly:
protected $appends = ['category_ids'];
public function categories(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(ArticleCategory::class);
}
public function getCategoryIdsAttribute()
{
return $this->categories->pluck('id');
}
Replied to I Need To Get Related Table In Array Format By 'with', But Pluck Not Work
thank you. I used your code, but get this error:
message: "Method Illuminate\Database\Eloquent\Collection::getCategoriesId does not exist."
my Article model:
class Article extends Model
{
use Translatable;
use Sluggable;
use HasTags;
public function sluggable(): array
{
return [
'slug' => [
'source' => ['title']
]
];
}
protected $fillable = ['publish', 'cover'];
public $translatedAttributes = ['title', 'content'];
public function categories(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(ArticleCategory::class);
}
protected $with = ['categories'];
public function getCategoriesId()
{
return $this->categories->pluck('article_category_id');
}
and my controller code is:
public function articleList(Request $request)
{
if ($request->ajax() && $request->is('admin/*')) {
$articles = Article::all()->getCategoriesId();
return $articles->paginate(20);
}
abort(404);
}
I changed the code as follows, but it still gives an error.
Method Illuminate\Support\Collection::addEagerConstraints does not exist.
public function categories(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(ArticleCategory::class);
}
protected $with = ['getCategoriesId'];
public function getCategoriesId()
{
return $this->categories->pluck('article_category_id');
}
Started a new Conversation I Need To Get Related Table In Array Format By 'with', But Pluck Not Work
Hi, article and articleCategory have many-to-many relations with the pivot table (article_article_category). in Article Model :
public function categories(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(ArticleCategory::class);
}
I need to get Articles with Categories. But categories must be arrays made of their IDs.
I try this code:
$articles = Article::query()->with(['categories' => function ($query) {
$query->pluck('article_category_id');
}]);
But it does not work properly and returns all the columns of the category as a collection. please help me
Replied to Version 8 Redirects
after rewrite ResponseLogin how to redirect to hme page blade? I use this code in ResponseLogin.php:
return $request->wantsJson()
? response()->json(['two_factor' => false])
: redirect()->intended("/");
and my home page is the blade. Unfortunately, it opens the home page in a pop-up dialog. and doesn't redirect to home with refresh page.
Started a new Conversation How To Set Dynamic Prefix For Fortify?
I did not find the ideal solution, no matter how much I searched. Unfortunately, only a fixed prefix can be placed in the config file. I need to set the prefix based on the language. The only solution I found was to move all the paths to the web.php. But this way it makes the web.php very crowded. Can you help me?
I change the language in localization middleware:
public function handle(Request $request, Closure $next)
{
$locale = $request->segment(1);
App::setLocale($locale);
return $next($request);
}