我有一个Laravel Web应用程序,包含两种类型的用户:
根据用户类型,他们可以查看和执行不同的操作.
顾客
以客户身份登录时,我的客户将看到不同的仪表板.
管理员
以admin身份登录时,我可以看到表中的用户列表
例,
目标: 我希望看到客户在点击列表中的某个用户时看到的内容.
我无法为此提出解决方案.
IMO
会Auth::user()->type适用于这种情况吗?
目标是Auth:user()->type == ‘customer’在实际时将页面呈现为Auth::user()->type == ‘admin’.我不完全确定我想做的事情是否可行.
我怎么在Laravel做那样的事情?
在Laravel刀片上有类似的东西吗?
Route::get('blade', function () {
return view('aMainPage');
});
Run Code Online (Sandbox Code Playgroud)
aMainPage.blade.php
@include('molecules.blocks.banner', ['background'=> '/image.jpeg'])
<h1>I am included</h1>
@endinclude
Run Code Online (Sandbox Code Playgroud)
/views/molecules/blocks/banner.blade.php
@if($background)
<section class="banner" style="background-image:url('{{$background}}');">
@else
<section class="banner">
@endif
<h1>Hello</h1>
@yield() {{- notice @yield here -}}
</section>
Run Code Online (Sandbox Code Playgroud)
期望的输出
<section class="banner" style="background-image:url('/image.jpeg');">
<h1>Hello</h1>
<h1>I am included</h1>
</section>
Run Code Online (Sandbox Code Playgroud)
这是上面呈现的内容
实际产出
<section class="banner" style="background-image:url('/image.jpeg');">
<h1>Hello</h1>
</section>
<h1>I am included</h1>
@endinclude
Run Code Online (Sandbox Code Playgroud) 我有这个版本: 流明(5.2.6)(Laravel Components 5.2.*)
所以这就是我想要实现的目标.我有一个默认的刀片模板default.blade.php,它由我的所有子视图扩展.
在我的内部default.blade.php有一个foreach循环,它向用户表达一些"全局"选项,其示例如下.
@foreach ($projects as $p)
<li><a href='$p->project_uid'>{{ $p->project_name }}</a></li>
@endforeach
Run Code Online (Sandbox Code Playgroud)
所以要实现这一点,我必须通过我的控制器中$projects的view('viewname', $data)或通过传递变量View::share('projects', $projects);__construct()
我是否有更好的方式在全球意义上做到这一点,以便不需要进行上述调用?
我所知道的一个选项是在我的视图中调用Model函数,但这违背了MVC的概念,因此并不理想.
任何有关该主题的指导将不胜感激,谢谢.
所以我尝试了ViewComposer解决方案,但遇到了一些问题.以下是我的作曲家和服务提供商注册.
配置/ app.php
App\Providers\ComposerServiceProvider::class,
Run Code Online (Sandbox Code Playgroud)
ComposerServiceProvider
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class ComposerServiceProvider extends ServiceProvider {
/**
* Register bindings in the container.
*
* @return void
*/
public function boot() {
// Using class based composers...
view ()->composer ( 'default', 'App\Http\ViewComposers\MasterComposer' );
}
/**
* Register the service provider.
*
* @return void …Run Code Online (Sandbox Code Playgroud) 我已经在实时服务器上成功部署了第一个laravel应用程序。除了我无法显示正在上传到/myproject_src/storage/app/public/myfolder1文件夹中的图像外,其他一切看起来都很不错
。
这是我在HostGator上的文件夹层次结构:
/ myproject_src /
这是所有laravel源文件(公用文件夹除外)
/public_html/mydomain.com/
这是我在公共目录中的所有内容
我以以下方式将文件路径存储到数据库中:
public/myfolder1/FxEj1V1neYrc7CVUYjlcYZCUf4YnC84Z3cwaMjVX.png
此路径与已上传到storage / app / public / myfolder1 /此文件夹的图像关联,并且是通过store('public/myfolder1');laravel方法生成 的。
我应该怎么做才能在img标签中正确显示图像:
<img src="{{ how to point to the uploaded image here }}">
Run Code Online (Sandbox Code Playgroud) 我正在构建laravel应用程序,我有这行代码,应使用旧输入和某些操作的结果,将用户重定向回刚提交的表单。
return back()->with(["result" => round($area, 2)])->withInput($request->all());
Run Code Online (Sandbox Code Playgroud)
问题是我仅在Blade中收到旧输入,并且该$result变量在视图中不可用。
这就是我尝试输出结果的方式:
<input type="text" name="result" value="{{isset($result)&&old('roofType')==0?$result:''}} ㎡ " class="form-control input-sm" >
Run Code Online (Sandbox Code Playgroud)
这是提交后我在视图中拥有的变量:
{{ dd(get_defined_vars()['__data']) }}:
array:7 [?
"__env" => Factory {#89 ?}
"app" => Application {#3 ?}
"errors" => ViewErrorBag {#169 ?}
"roofName" => "Acoperis intr-o apa"
"roofType" => "1"
"roofFolder" => "A1"
"baseFields" => array:3 [?
0 => "L"
1 => "l"
2 => "H"
]
]
Run Code Online (Sandbox Code Playgroud) 我正在使用分页进行分页,我想为$items->links()Blade中的刀片添加自定义标记,如下所示:
<div class="pagination-wrapper">
{{ $items->links() }}
</div>
Run Code Online (Sandbox Code Playgroud)
如何检查是否显示分页链接,以免打印出空白的分页包装纸?
我的Laravel刀片模板中出现此错误
htmlspecialchars()期望参数1为string,给定数组
我试图将数组转换为刀片模板中的字符串.
这是代码
<script>
var value = {{ $sliderImageDataArray }}.toString()
window.MedicPressSliderCaptions = value;
</script>
Run Code Online (Sandbox Code Playgroud)
这里$silderImageDataArray存储的变量和值在哪里.
这是$silderImageDataArray价值
[{"title":"First title","text":"<p><span id=\"hs_cos_wrapper_module_1498510869515998\" class=\"hs_cos_wrapper hs_cos_wrapper_widget_container hs_cos_wrapper_type_widget_container\" data-hs-cos-general-type=\"widget_container\" data-hs-cos-type=\"widget_container\">First title<\\\/span><\\\/p>\n<p><a class=\"btn btn-secondary\" href=\"http:\\\/\\\/localhost\\\/sencare\\\/book-appoinment\\\/\" target=\"_self\"> Make An Appointment <\\\/a>\\u00a0<a class=\"btn btn-light\" href=\"http:\\\/\\\/localhost\\\/sencare\\\/our-doctors\\\/\" target=\"_self\"> Our Doctors<\\\/a><\\\/p>\n","is_video":false},{"title":"Second","text":"<p><span id=\"hs_cos_wrapper_module_1498510869515998\" class=\"hs_cos_wrapper hs_cos_wrapper_widget_container hs_cos_wrapper_type_widget_container\" data-hs-cos-general-type=\"widget_container\" data-hs-cos-type=\"widget_container\">Second<\\\/span><\\\/p>\n<p><a class=\"btn btn-secondary\" href=\"http:\\\/\\\/localhost\\\/sencare\\\/book-appoinment\\\/\" target=\"_self\"> Make An Appointment <\\\/a>\\u00a0<a class=\"btn btn-light\" href=\"http:\\\/\\\/localhost\\\/sencare\\\/our-doctors\\\/\" target=\"_self\"> Our Doctors<\\\/a><\\\/p>\n","is_video":false}]
Run Code Online (Sandbox Code Playgroud) 令人怀疑的是,我尝试使用不同的方法自行解决,但没有一个能给我带来预期的结果。
当我在项目的数据库中保存文本类型的变量时,就会出现问题。它使用换行符保存它,实际上,当我尝试从其中一种视图对其进行编辑时,它会尊重这些跳转。当我想blade.php在所有文本都没有任何换行符的视图中显示它时,就会出现问题。
我使用了诸如nl2br ()或的不同功能str_replace,它们所做的只是将/ n更改为br标签的换行符,而不是应用这些换行符,而是将它们写在屏幕上文本旁边。
我不知道是否应该在服务器上执行对变量的更改或修改,然后将其发送到视图,而不是在视图中执行{{nl2br ($ user-> proffile)}}或使用str_replace。
首先得到英语的宽恕,并在此先感谢您的帮助
i want to access the defined relation in my blade view and show it i am doing like this in my invoice model
public function users() {
return $this->hasone('App\Client','id','client_id');
}
Run Code Online (Sandbox Code Playgroud)
and here in invoice controller
public function show(Invoice $invoice)
{
$clients = Invoice::with('users')->get();
return view('admin.invoices.show', compact('invoice', $invoice),compact('clients',$clients));
}
Run Code Online (Sandbox Code Playgroud)
and finally in my view i did this
<td>{{ $clients->users->first()->title }}</td>
Run Code Online (Sandbox Code Playgroud)
but when i try to view i get this error
Property [users] does not exist on this collection instance
Run Code Online (Sandbox Code Playgroud)
when i …
laravel-blade ×10
laravel ×9
php ×9
laravel-5 ×3
blade ×2
controller ×1
html5 ×1
laravel-5.1 ×1
laravel-5.2 ×1
laravel-5.3 ×1
laravel-5.4 ×1
lumen ×1
lumen-5.2 ×1
view ×1