590 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 Add To New Collection From Each Loop
With the ->flatten(1);
i get something like :
[
{
"x": 74
},
{
"y": 172
},
{
"x": 10
},
{
"y": 49
}
]
And with ->flatMap
i get something like :
{
"2020-11-25": {
"y": 172
},
"2020-11-26": {
"y": 49
}
}
( only the last values from each date ).
Started a new Conversation Add To New Collection From Each Loop
I have the following piece of code :
$callReport = array();
$callResult->each(function ($item) use (&$callReport) {
$callReport[$item->date][$item->callStatus] = $item->count;
});
The $callReport
result is :
{
"2020-11-25": {
"x": 74,
"y": 172,
},
"2020-11-26": {
"x": 10,
"y": 49,
}
}
But when i try with the collect methods :
$callReport = collect();
$callResult->each(function ($item) use (&$callReport ) {
$callReport->push($item->date, collect([$item->callStatus => $item->count]));
});
I can't reach the same result :
[
"2020-11-25",
{
"x": 74
},
"2020-11-25",
{
"y": 172
},
"2020-11-26",
{
"x": 10
},
"2020-11-26",
{
"y": 49
}
]
How i can get the same result as the first one with the array using the collect methods?
Started a new Conversation Same API Top Level Meta In JsonResource Single & Collection
Hello,
I have the following controller :
public function index()
{
$products = Product::where('idp', '=', '1958213')->get();
return ClientProductResource::collection($products)->additional(['something' => [
'key' => 'value',
]]);
}
public function show(Product $product)
{
return new ClientProductResource($product);
}
And the following Resource :
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class ClientProductResource extends JsonResource
{
public function toArray($request)
{
return [
'idp' => $this->idp,
'description' => $this->description
];
}
public function with($request)
{
return [
'something' => [
'key' => 'value',
],
];
}
}
The issue is that i need to put the "something" twice to get it in the json response, once for index method in additional
, and once for "show" in public function with
method.
If i remove public function with
method, i can't see it in public function show
response.
If i remove it from ->additional([])
, i can't see it in public function index
response.
How or where i can put the "something" only once, so i can see it in both controller methods?
Thank you
Replied to Controller Constructors And The Artisan Route:list Command
Hello,
I have the same issue, when running php artisan route:list
I have one Controller with this constructor:
public function __construct(Request $request)
{
$this->middleware('connectorGroup');
$this->authGroup = AuthGroups::findOrFail($request->route('authGroup'));
$this->authCategory = $this->authGroup->category;
}
Even if i check in the middleware connectorGroup
:
public function handle($request, Closure $next)
{
if($request->route('authGroup')){
return $next($request);
}
}
I get this error :
Illuminate\Database\Eloquent\ModelNotFoundException
No query results for model [App\AuthGroups].
If i change only to find
method, the next row fails :
ErrorException
Trying to get property 'category' of non-object
The real question is, there is a nice workaround to fix this issue?
Started a new Conversation Handle/Render Response In Custom Exceptions
Hello,
I make a new exception :
php artisan make:exception GuzzleGeneralException
I have a simple Guzzle Request :
try {
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle123456');
} catch (RequestException $ex) {
throw new GuzzleGeneralException($ex);
} catch (ConnectException $ex) {
throw new GuzzleGeneralException($ex);
}
How i can do something like extending the Handler
with my GuzzleGeneralException
, passing the exceptions to it and write inside all the logic that usually you write in Handler
?
Something like this :
class GuzzleGeneralException extends Exception
{
public function render(Throwable $exception)
{
if ($exception instanceof RequestException) {
return response()->json();
}else if ($exception instanceof ConnectException) {
return response()->json(
}
}
}