Skip to content
This repository has been archived by the owner on Jun 1, 2019. It is now read-only.

Unable to clear log using Activity::cleanLog(); #31

Closed
nehulagr opened this issue Feb 13, 2016 · 4 comments
Closed

Unable to clear log using Activity::cleanLog(); #31

nehulagr opened this issue Feb 13, 2016 · 4 comments

Comments

@nehulagr
Copy link

Thank you for such a nice module. It works great. Its simple and working.

I just need to know why Activity::cleanLog(); is not working? Its showing this error

BadMethodCallException in Builder.php line 2161:
Call to undefined method Illuminate\Database\Query\Builder::cleanLog()

I am just using it normally, like below i have a controller with name LogsController and i have used use Spatie\Activitylog\Models\Activity; in which i have just 2 functions as below:

public function index()
    {
        $latestActivities = Activity::with('user')->latest()->get();
        return view('logs.logs')->with('logs', $latestActivities);
    }

    public function clearlog(){
        Activity::cleanLog();
        Activity::log('Logs cleared By : '.Auth::user()->name);
        \Session::flash('success', 'Logs deleted successfully');
    }

I have defined a route for this:

Route::get('logs/clearlog', 'LogsController@clearlog');
Route::resource('logs', 'LogsController');

I dont know where i am making mistake. Please help me get this thing straight. I am new to laravel.

Thank you!

@freekmurze
Copy link
Member

Did you import the Activity-facade at the top of your file?

use Activity;

@nehulagr
Copy link
Author

No its not allowing me to import two files. I have already import

use Spatie\Activitylog\Models\Activity;

What should i do?

@nehulagr
Copy link
Author

Here is how my full controller looks like...

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Auth;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Spatie\Activitylog\Models\Activity;
//use Activity;

class LogsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $latestActivities = Activity::with('user')->latest()->get();
        return view('logs.logs')->with('logs', $latestActivities);
    }

    public function headerLogs()
    {
        $latestActivities = Activity::with('user')->latest()->limit(10)->get();
        return view('layouts.header')->with('logs', $latestActivities);
    }

    public function clearlog(){
        Activity::cleanLog();
        Activity::log('Logs cleared By : '.Auth::user()->name);
        \Session::flash('success', 'Logs deleted successfully');
        return redirect('logs');
    }
}

@sebastiandedeyne
Copy link
Member

You'll need to rename one of your imports with the as keyword.

use Activity;
use Spatie\Activitylog\Models\Activity as ActivityModel;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants