Closed LeonardoSartor closed 2 years ago
Hi @LeonardoSartor Thanks for using OpenGraph. I checked the library its working fine with Laravel 8.x also tried with validation logic. Seems to be working fine. Do you mind sharing some more code snippet how you are trying to use the library, or share a sandbox code to debug it.
Here is the snippet I have tried with:
Route::get('/fetch', function (Request $request) {
$validator = Validator::make($request->all(), [
'link' => 'required',
]);
if (!$validator->fails()) {
$data_group = OpenGraph::fetch($request->link);
$validator->after(function ($validator) use ($data_group) {
if(empty($data_group['title'])) {
$validator->errors()->add('link', 'Error');
}
return response()->json($data_group);
});
}
});
Few things you can check:
Thank you very much @shweshi! My mistake was calling it inside a static function... What a silly mistake... but for a beginner, I think it's okay!
I solved it by changing the code to:
if (!$validator->fails()) {
$data_group = new OpenGraph();
$data_group = $data_group->fetch($request->link);
$validator->after(function ($validator) use ($data_group) {
if(empty($data_group['title'])) {
$validator->errors()->add('link', 'Error.');
}
});
}
From my heart, thank you very much for your help, it will be of great help for a personal project, it made me see the error and fix it!
@LeonardoSartor Glad it helped.
Happy Coding
Hello how are you? I started getting this error when using...
[2022-03-18 21:45:05] local.ERROR: Using $this when not in object context {"exception":"[object] (Error(code: 0): Using $this when not in object context at [...]back-end\vendor\shweshi\opengraph\src\OpenGraph.php:12)
Laravel 8.x My code:
if (!$validator->fails()) { $data_group = OpenGraph::fetch($request->link); $validator->after(function ($validator) use ($data_group) { if(empty($data_group['title'])) { $validator->errors()->add('link', 'Error'); } }); }
I don't understand its origin or how to solve it...