Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wontoneesaju's avatar

Custom Class

Hi,

I am having one custom class called /app/Library/Angular.php. Code is look like this way

namespace App\Library; /* Custom Class to use angular js in laravel framework */ class angularbind{

/**
 * This function to bind the angular data in a curly braces
 * This help the bind the NG data
 *
 */
function binding($bindtext)
{
    return $bindtext;
}

}

Inside the composer i am having this line :

"files": [ "app/Library/Angular.php" ],

Now if i will use namespace directly $test=new \app\Library\Angular\angularbind; inside the blade template it always throw one error called class not found.

0 likes
15 replies
wontoneesaju's avatar

In blade -> view i am using this line $test=new \App\Library\Angular\angularbind;

topvillas's avatar

If the class is somewhere in the app folder then you don't need to reference in composer.json at all.

If not then you need to load it with PSR4 not as a file.

topvillas's avatar

You don't need to if it's in the app folder. Everything already autoloaded.

Don't instantiate classes in your Blade file. Do it in the controller and pass it in.

wontoneesaju's avatar

"Do it in the controller and pass it in. " can you help me how to write that?

topvillas's avatar

First of all, capital case your class.

use App\Library\Angular\AngularBind;

public function something() {
    $bind= new AngularBind;
    return view('yourview', compact('bind'));
}

All of this is Laravel 101. You should watch some introductory videos.

wontoneesaju's avatar

i have to write this in

Http/Controller/Controller.php right ?

wontoneesaju's avatar

ok done. now how can i load this in my blade template? last question

topvillas's avatar

You don't, the class is instantiated in the controller and passed in. Just use it.

wontoneesaju's avatar

yes that class is instantiated.

Name:

  {{na}}

</p>

i am binding a angular js ng-modal with that function.

wontoneesaju's avatar

https://prnt.sc/j23cw7 see this. if we are using directive like {{}} laravel thinking it like some function. So when we are passing this to php echo whole my angular codes works well inside the laravel framework.

topvillas's avatar

This started out as how to correctly autoload classes using PSR4 in Composer. I'm afraid I don't know anything weird Angular bindings using Blade.

wontoneesaju's avatar

:) ah ok it works, for instance i show you.

for instance normally we bind angular like {{saju}} but laravel feel this as a own function like we are having {{ asset etc...

so if we will write angular binding with

topvillas's avatar

Use @{{ saju }} and Blade will ignore it.

1 like

Please or to participate in this conversation.