How can I use “prep_url” from codeigniter inside m

2019-08-17 15:11发布

问题:

I add the function "prep_url" from codeigniter to my laravel project like here:

Laravel add http to urls

If I do it in my Controller like this:

$website = example.com;
$url = prep_url($website);

and then in my view I can do it like this:

{{$url}}

it shows me this: http://example.com

so everything works :)

but I have a problem

I have the table users and there all users have a website

in my controller I do it like this:

$user = DB::table('users')->get();
return view('user/einzelansicht' ['user' => $user] );

and in my view I can show my user with

{{$user[1]->name}}
{{$user[1]->website}}

how can I use prep_url here?

because I already did this in my view:

{{prep_url($user[1]->website);}}

but it tells me semicolons are not allowed and without the semicolon it does not work

then I tried in my controller this:

$website = $user->website;
$url = prep_url($website);

but this doesn't work too

so how can I do this?

回答1:

Maybe your "website" attribute is not a string.

Try

prep_url(json_encode($u[1]->website));