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

mmings's avatar

Call to show method changing where application looks for application resources

The call to index() works fine and produces html ex: http://sign.vm-host.net/scripts The call to show() will add "documents" to url ex: http://sign.vm-host.net/documents/scripts

public function index()
{
    $documents = App\User::find(Auth::user()->id)->documents->where('parent_id','=',0)->toArray();

    return view('documents.index', compact('documents'));
}

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
    //
    return 'Create';
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
  $request['user_id'] = Auth::user()->id;
    if ($request->bytes == null) {
        $request->bytes = 0;
    }

    $document = new App\Document;
    $document->user_id = $request->user_id;
    $document->parent_id = $request->parent_id;
    $document->type = $request->type;
    $document->name = $request->name;
    $document->bytes = $request->bytes;
    $document->extension = $request->extension;
    $document->storage_key = $request->storage_key;
    $document->save();

}

public function show($id)
{

    $documents = App\User::find(Auth::user()->id)->documents->where('parent_id','=',$id)->toArray();
    return View::make('documents.index')->with('documents',$documents);
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($id)
{
    //
    return 'edit';
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $id)
{
    //
    return 'update';
}

/**
 * Remove the specified resource from storage.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function destroy($id)
{
    //
    return 'destroy';
}

}

0 likes
5 replies
mmings's avatar

Can't figure out the show method problem

Snapey's avatar

you need to make your assets relative to the root folder by starting them with /

if you just say 'scripts' then this is relative to the current url so it tries to load /document/scripts

1 like
jekinney's avatar

To array in oop? The issue is more then likely in your routes file or link.

mmings's avatar
mmings
OP
Best Answer
Level 1

The issue was actually in my layouts template ex: href="css*.css" like Snapey suggested. Easily corrected by href="{{ url('css*.css') }}"

jekinney...I am kinda new to oop. What is the problem using toArray()?

Please or to participate in this conversation.