我一直在尝试在搜索栏中填充一些小图片。但是,它没有显示。以下是我的代码,请提供帮助。
Results.blade.php
@extends('layouts.app')
@section('content')
<h3> Your search for "{{ Request::input('query') }}"</h3>
@if (!$users->count())
<p>No results found, sorry.</p>
@else
<div class="row">
<div class="col-lg-12">
@foreach ($users as $user)
@include('user/partials/userblock')
@endforeach
</div>
</div>
@endif
@stop
userblock.blade.php
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" alt="{{ $user->getNameOrUsername() }}" src="
{{ $user->getAvatarUrl() }}">
</a>
<div class="media-body">
<h4 class="media-heading"><a href="#">{{ $user->getNameOrUsername() }}</a></h4>
@if ($user->location)
<p>{{ $user->location }}</p>
@endif
</div>
</div>
User.php
<?php
namespace Kermode;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'first_name','last_name', 'email', 'password','gender',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function getName()
{
if ($this->first_name && $this->last_name) {
return "{$this->first_name} {$this->last_name}";
}
if ($this->first_name) {
return $this->first_name;
}
return null;
}
public function getNameOrUsername()
{
return $this->getName() ?: $this->username;
}
public function getFirstNameOrUsername()
{
return $this->first_name ?: $this->username;
}
public function getAvatarUrl()
{
return "https://www.gravatar.com/avatar/{{ md5($this->email) }}
?d=mm&s=40";
}
}
SearchController.php
<?php
namespace Kermode\Http\Controllers;
use DB;
use Kermode\User;
use Illuminate\Http\Request;
class SearchController extends Controller
{
public function getResults(Request $request)
{
$query = $request->input('query');
if (!$query) {
return redirect()->route('home');
}
$users = User::where(DB::raw("CONCAT(first_name,' ', last_name)"),
'LIKE', "%$query%")
->orWhere('email', 'LIKE' , "%$query%")
->get();
return view('search.results', compact('users'));
}
}
感谢您的帮助。我不熟悉基于Web的应用程序。xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx xxx
答案 0 :(得分:0)
在您的User类中,尝试不使用刀片。
public function getAvatarUrl()
{
$md5Email = md5($this->email);
return sprintf("https://www.gravatar.com/avatar/%s?d=mm&s=40", $md5Email);
}
其他提示: