0

I'm little bit confused, I get Call to undefined method Illuminate\Database\Eloquent\Builder::getAbsolutePath() (View: C:\Users\rust\Desktop\projectName\resources\views\container\index.blade.php)

And my show method in my ContainerController.php looks like this :

public function show($args = '')
    {
        if($document = Document::where('key', $args)->first()) {
            return response()->download(storage_path('app'). DIRECTORY_SEPARATOR . $document->getAbsolutePath());
        }

        $items = explode('/', $args);
        $department = Auth::user()->department;

        if (Auth::user()->hasRole('Root')) {
            $department = Department::where('slug', '=', $items[0])->first();
            $items = array_slice($items, 1);
        }

        if($department == null) {
            return redirect('/');
        }

        if(file_exists(storage_path('app' . DIRECTORY_SEPARATOR . $department->slug . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $items)))
            && !is_dir(storage_path('app' . DIRECTORY_SEPARATOR . $department->slug . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $items)))) {

            return response()->file(storage_path('app' . DIRECTORY_SEPARATOR . $department->slug . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $items)));
        }

        $current_parent = 0;
        foreach ($items as $item) {
            $container = Container::where('slug', '=', $item)
                ->where('parent_id', '=', $current_parent)
                ->where('department_id', '=', $department->id)
                ->first();
            if(!$container) abort(404);
            $current_parent = $container->id;
        }

        $contents = Container::where('parent_id', '=', $current_parent)
            ->where('department_id', "=", $department->id)
            ->get();
        if (!($container = Container::find($current_parent))) {
            $container = $department;
        }

        return view('container.index', compact('container', 'contents', 'args'));
    }

I don't know what I did wrong, but I'm a little bit lost right now

Michael Dodd
  • 10,102
  • 12
  • 51
  • 64
  • Can you show us your `container/index.blade.php`? – Chin Leung Jun 21 '19 at 14:09
  • It says your error is in view, are you making any calls in the view? – shahburhan Jun 21 '19 at 14:09
  • Should go without saying, but please don't vandalise your question. It'll be rolled back otherwise. – Michael Dodd Jul 03 '19 at 08:08
  • @rust That's because your question has an answer and that answer has been positively received. To be able to delete the question after the fact would be unfair on the time Vikash has spent trying to help you on this question. You can find the conditions for being able to self-delete a question [on the help pages](https://stackoverflow.com/help/deleted-questions) – Michael Dodd Jul 03 '19 at 08:54

1 Answers1

0

In your code... $document is the laravel collection.. not file object. Try load the file and then call getAbsolutePath() with that.

// code snippts.

if($document = Document::where('key', $args)->first()) {
            return response()->download(storage_path('app'). DIRECTORY_SEPARATOR . $document->getAbsolutePath());
}

Edited: And in your view you are also using the collection with $container->getAbsolutePath() at line no: 65.

Vikash Pathak
  • 3,444
  • 1
  • 18
  • 32