Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined method Illuminate\Support\Facades\Log::save()

I created 'Log' class in app/models :

class Log extends Eloquent {

    public function user() {
        return $this->belongsTo('user');
    }

}

When i try to save log object in my controller i got this error (Call to undefined method Illuminate\Support\Facades\Log::save() ) I thik because in (app/config/app) in providers laravel define Log class => 'Log'=> 'Illuminate\Support\Facades\Log',.

How can i resolve this problem without change class name ?

like image 872
AiD Avatar asked Jan 24 '26 21:01

AiD


1 Answers

Yes the problem is indeed a conflict with the Log facade alias. To fix it use namespaces:

<?php namespace YourApp;

class Log extends Eloquent {

    public function user() {
        return $this->belongsTo('user');
    }

}

And then you can use your class like so:

$log = new YourApp\Log();

You could of course rename the alias name, but namespacing your classes is a much better approach.

like image 66
Bogdan Avatar answered Jan 26 '26 23:01

Bogdan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!