BadMethodCallException in View.php line 394: Method [get] does not exist on view - laravel-5.3

I am getting this error and I can't figure out what is causing the error, can someone help me to solve this?
Here is the code
public function showClassInformation(Request $request)
{
return response($this->ClassInformation()->get());
}
//===============================================================
public function ClassInformation()
{
$classes = MyClass::join('academics','academics.academic_id','=','classes.academic_id')
->join('levels','levels.level_id','=','classes.level_id')
->join('shifts','shifts.shift_id','=','classes.shift_id')
->join('times','times.time_id','=','classes.time_id')
->join('batches','batches.batch_id','=','classes.batch_id')
->join('groups','groups.group_id','=','classes.group_id');
return view('class.classinfo',compact('classes'));
}

Related

how to fetch files of user following by user

public function followers()
{
return $this->belongsToMany('App\User', 'follower_following', 'following_id', 'follower_id')
->select('id', 'uname', 'name');
}
public function following()
{
return $this->belongsToMany('App\User', 'follower_following', 'follower_id', 'following_id')
->select('id', 'uname', 'name');
}
public function files(){
return $this->hasMany(Files::class)
->orderBy('created_at');
}
how to i fetch files of user followig
i have tried this method
$file = Files::whereIn('user_id',$followers)
->with('user')
->latest()
->limit(10)
->get();
but it shows undefined $followers
If I understood it well, you want to fetch files of user's followers.
Have you tried something like this:
App\User::with('followers.files')->find(1);

How to do proper error handling in services

I am writing a small service for a Symfony 4 project
and I'm just wondering if my error handling is a good idea.
My class currently looks like this:
namespace App\Service;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\;
/**
* Class XMLHelper
* #package App\Service
*/
class XMLHelper
{
public function getContent(string $path): array
{
$fileSystem = new Filesystem();
if ($fileSystem->exists($path)) {
libxml_use_internal_errors(true);
$object = simplexml_load_file($path);
if ($object === false) {
$str = 'Failed loading XML: ';
foreach(libxml_get_errors() as $error) {
$str = $error->message . ', ';
}
throw new \UnexpectedValueException($str);
}
return $object;
} else {
throw new \FileNotFoundException('File ' . $path . ' not found.');
}
}
}
My question is, do I need that at all? Will symfony not throw
out an error anyway. Is the output not superfluous? How do
you do it the best or generally correctly? If you have own
Exceptions in Services.
IMO you should never hesitate to throw an exception when appropriate. Your code looks just fine, it provides an exhaustive information about the encountered exeptions.
There is nothing to do with Symfony ifself, it up to your code to throw right exceptions in right places.
Hope this helps.
P.S. And don't forget to libxml_clear_errors();

Symfony2 set class variable with init or construct methods

Have recently been using Symfony2 after using ZF for some time.
I am having problems trying to do something relatively simple, I think.
The following code is within a controller:
private $current_setid = "";
public function __construct() {
$current_set = $this->getCurrentSet();
if ($current_set == "") {
return $this->redirect($this->generateUrl('selectset'));
}
$this->current_setid = $current_set;
}
public function getCurrentSet() {
$session = $this->get("session");
$set = $session->get('set');
return $set;
}
public function setCurrentSet($setid) {
$session = $this->get("session");
$session->set('set', "$setid");
}
If I use __construct() I get errors like:
Fatal error: Call to a member function get() on a non-object in
I have tried using __init() and init() both of which do not seem to get called.
Can anyone point me in the right direction? Is there a simple way to do this or do I have to look into event listeners?
Have you tried getting your session like they do in official documentation?
$session = $this->getRequest()->getSession();
$foo = $session->get('foo');
Basically get fetch dependencies from container and container in the Controller is injected using setter dependency injection. You just not have container in the time of __construct yet.
Just ended up opting for placing a check in every method in the class. Seems silly to have to do that but I find I often have to do that in Symfony2 with the lack of init, postDispatch type methods like ZF has.
Even trying to remove the check to another method was counter productive as I still had to check the return from that method as $this->redirect does not seem to work unless it is within an Action method. For example:
public function isSetSet() {
$current_set = $this->getCurrentSet();
if ($current_set == "") {
$url = $this->generateUrl('selectset');
return $this->redirect($url);
}
return TRUE;
}
public function someAction() {
$check = $this->isSetSet();
if($check != TRUE){
return $check;
}
...
}
So each method needs that 4 line check but the whole check can be done in 4 lines anyway so no need for that extra method:
public function anotherAction() {
$current_setid = $this->getCurrentSet();
if ($current_setid == "") {
return $this->redirect($this->generateUrl('selectset'));
}
...
}

Drupal hook_menu_alter system error

Using the following code:
function mymodule_menu_alter(&$items) {
if (isset($items['node/add/page'])) {
$items['node/add/page']['access arguments'] = FALSE;
}
}
I get the following error:
warning: Missing argument 1 for node_access() in
/var/www/vhosts/mysite.co.uk/httpdocs/modules/node/node.module on line
2011.
The code actually works and does what I need it to do but the error concerns me and confuses my site users.
I am not sure what the issue is or how to resolve it. Can anyone offer some assistance?
access arguments needs to be an array:
function mymodule_menu_alter(&$items) {
if (isset($items['node/add/page'])) {
$items['node/add/page']['access arguments'] = array();
}
}
If you're trying to deny access to your page to absolutely anyone you should use the access callback key instead:
function mymodule_menu_alter(&$items) {
if (isset($items['node/add/page'])) {
$items['node/add/page']['access callback'] = FALSE;
}
}

Actionscript 3 Null Object Error Message

I am building a AS3 only project and got runtime error that said "Cannot access a property or method of a null object reference."
Here is my code:
main.as
public class videoMain extends Sprite{
private var videoPlayer:Player;
public function videoMain (){
loadPlayer()
loadProgress();
}
private function loadProgress():void{
//the code below gave me null object error.....
var byteLoaded:Number=videoPlayer.videoBytesLoaded; //the problem code
var byteTotal:Number=videoPlayer.videoBytesTotal; //the problem code
var percent:Number=Math.floor(byteLoaded/byteTotal)*100;
}
private function loadPlayer():void{
videoPlayer= new Player();
videoPlayer.createPlayer();
}
}
Player.as
public function createPlayer():void{
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
_loader.load(new URLRequest(playerType));
}
public function get videoBytesLoaded():Number{
return _Player.getVideoBytesLoaded(); //youtube api method
}
public function get videoBytesTotal():Number{
return _Player.getVideoBytesTotal; //youtube api method
}
private function onLoaderInit(event:Event):void {
_Player=_loader.content;
//only show part of codes....
}
I appreciate any help....Thanks!!!!!
_Player is only defined after the Event.INIT has fired so any call before the _Player value is defined will throw an error.
You should, at the minimum , have this:
public function videoMain (){
loadPlayer()
}
private function onLoaderInit(event:Event):void {
_Player=_loader.content;
//only show part of codes....
loadProgress();
}
but progress events are not static so really you should have an enterFrame event listener in order to listen to the changing values...
private function onLoaderInit(event:Event):void {
_Player=_loader.content;
//only show part of codes....
addEventListener(Event.ENTER_FRAME , enterFrameListener);
}
private function enterFrameListener(event:Event):void
{
loadProgress();
// and here you add some way to remove this event listener when
// the video is fully loaded
}

Resources