Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

How can I use "prep_url" from codeigniter inside my View in Laravel?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Maybe your "website" attribute is not a string.

Try

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...