the Error App\View\Components\vodplay::render(): Return value must be of type Illuminate\Contracts\View\View|Closure|string, none returned is showing is component class, code was working and I didn’t change this class, I don’t know whats wrong, please help
Error in flareapp: https://flareapp.io/share/lm2KRJEP
this component class:
<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
use App\Models\Video;
use App\Models\Order;
use App\Models\User;
use Shetabit\Multipay\Invoice;
use Shetabit\Payment\Facade\Payment;
use Illuminate\Support\Facades\URL;
use Carbon\Carbon;
class vodplay extends Component
{
/**
* Create a new component instance.
*/
public $iding;
public function __construct($iding)
{
//
$this->id = $iding;
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
$price = Video::where('id',$this->id)->first();
$price = $price->price;
// dd($price);
$videodata = Video::where('id',$this->id)->first();
$phonenumber = Session('phonenumber');
$ispaidcount = Order::where('userphone',$phonenumber)->where('contentid', $this->id)->count();
// بررسی اینکه آیا پرداختی داشته یا محصول رایگان بوده ؟
if ($price == '0' || $price == NULL) {
return view('components.vodplay')->with('videodata',$videodata);
} elseif ($ispaidcount > 0) {
$timelimit = Order::where('userphone',$phonenumber)->where('contentid', $this->id)->orderBy('starttime','asc')->first();
$starttime = $timelimit->starttime;
$limit = $timelimit->seconds;
$carbon = new Carbon($starttime);
$now = Carbon::now();
$endtime = $carbon->addSeconds($limit);
// dd($starttime,$limit,$endtime);
// بررسی اینکه آیا پرداختی اعتبار دارد
if ($now->greaterThan($endtime)) {
$preurl = URL::previous();
Session(['preurl'=>$preurl]);
Session(['contentid'=>$this->id]);
// Do all things together in a single line.
return Payment::purchase(
(new Invoice)->amount($price),
function($driver, $transactionId) {
// Store transactionId in database.
// We need the transactionId to verify payment in the future.
}
)->pay()->render();
} else {
return view('components.vodplay')->with('videodata',$videodata);
}
}
}
}
this code should create an invoice for user or allow user to watch video if payment was accepted.
>Solution :
Basically none of your if conditions are hit, when you typehint it to return something and nothing is returned, that is the error you get.
Return a default view and you will be fine, but probably the reason why your if statements are not hit is just as important.
if ($price == '0' || $price == NULL) {
// something
} elseif ($ispaidcount > 0) {
// something else
}
return view('components.default'); // or whatever view could be the default.