我正在对用户执行权限检查以确定他们是否可以查看页面.这涉及首先通过一些中间件传递请求.
我遇到的问题是我在将数据返回到视图本身之前,在中间件和控制器中复制相同的数据库查询.
以下是设置示例;
- routes.php
Route::get('pages/{id}', [
'as' => 'pages',
'middleware' => 'pageUser'
'uses' => 'PagesController@view'
]);
Run Code Online (Sandbox Code Playgroud)
- PageUserMiddleware.php(类PageUserMiddleware)
public function handle($request, Closure $next)
{
//get the page
$pageId = $request->route('id');
//find the page with users
$page = Page::with('users')->where('id', $pageId)->first();
//check if the logged in user exists for the page
if(!$page->users()->wherePivot('user_id', Auth::user()->id)->exists()) {
//redirect them if they don't exist
return redirect()->route('redirectRoute');
}
return $next($request);
}
Run Code Online (Sandbox Code Playgroud)
- PagesController.php
public function view($id)
{
$page = Page::with('users')->where('id', $id)->first();
return view('pages.view', ['page' => $page]); …Run Code Online (Sandbox Code Playgroud) 我有一个React Native,React混合应用程序.对于React Native,我使用的是react-native-elements.
我的应用程序使用Expo运行,并使用react-native init构建.我得到材料图标(缺少)RSD;
通过大量搜索,我找到了@ expo/vector-icons,但似乎没有用.我的App.js看起来像这样;
import React from 'react'
import { Font, AppLoading } from 'expo'
import { MaterialIcons } from '@expo/vector-icons'
import HybridApp from './src/App'
export default class NativeApp extends React.Component {
constructor() {
super()
this.state = {
fontsAreLoaded: false
}
}
async componentWillMount() {
await Font.loadAsync(MaterialIcons.font)
this.setState({ fontsAreLoaded: true })
}
render() {
const { fontsAreLoaded } = this.state
return !fontsAreLoaded ? <AppLoading /> : <HybridApp />
}
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我正在等待加载字体......一切都无济于事.
我想在尝试输出文件之前检查资产{{asset}}是否存在.
我在google之后尝试过一些东西,但似乎没有一个在Laravel 5.0上运行.
我想象的一个例子(在前端刀片视图中)看起来像;
@if(asset(path-to-asset))
<img src="image-path"/>
@else
<img src="no-image-path"/>
@endif
Run Code Online (Sandbox Code Playgroud)
谢谢
假设我有一个基本的、基本级别的 StyledText 组件;
import styled from 'styled-components/native'
const StyledText = styled.Text`
font-size: 16px;
color: pink;
`
export default StyledText
Run Code Online (Sandbox Code Playgroud)
然后我有一个处理标题的 Text 组件的扩展;
import StyledText from '../StyledText'
const StyledTitle = StyledText.extend`
color: black;
font-weight: bold;
font-size: 20px;
`
export default StyledTitle
Run Code Online (Sandbox Code Playgroud)
简单到此为止。
我需要做的是根据设备的大小动态增加字体大小。一个简单的函数就可以解决这个问题。但是有没有一种方法可以让调整大小函数或 util 只能从主 StyledText 组件调用一次,而不是在整个应用程序中重复使用 StyledText 扩展的每个实例?
只是为了澄清,围绕增加大小的逻辑没有问题,问题是在每次使用任何扩展 Text 组件时导入和使用 util。
例如,util 可能如下所示;
// utils
export function fontSize(size) {
// do some logic here to increase the size, or whatever...
return `
font-size: ${size}px;
`
}
Run Code Online (Sandbox Code Playgroud)
然后像这样使用;
import styled …Run Code Online (Sandbox Code Playgroud) 我不确定这是否可行;我们有各种主题颜色(颜色...),它们随着每个页面的变化而变化。我们还利用了大量内容加载而无需页面刷新。
我想使用 chrome 移动浏览器中可用的主题颜色元标记来设置选项卡颜色。
由于我们的页面不刷新,我希望这种颜色能够反映新页面的背景颜色。我可以删除原始元并使用以下内容添加新元;
function updateMetaThemeColor(theme) {
var themeColor;
if(theme == 'theme-1') {
themeColor = '#f4dcdc'
} else if(theme == 'theme-2') {
themeColor = '#f0e8dd';
} else if(theme == 'theme-3') {
themeColor = '#d5e7f0';
} else if(theme == 'theme-4') {
themeColor = '#f6efb9';
} else if(theme == 'theme-5') {
themeColor = '#eaeae8';
} else if(theme == 'theme-6') {
themeColor = '#f8e3c7';
} else if(theme == 'theme-7') {
themeColor = '#cde8e8';
}
//remove the current meta
$('meta[name=theme-color]').remove();
//add the new …Run Code Online (Sandbox Code Playgroud) 我正在开发一个相当复杂的多语言网站,它将根据html语言环境呈现不同的部分内容.
我有一个部分结构,将使用附加到文件名的区域设置来选择正确的.例如;
{% include '@BundleName/Layout/Text/_partial-name.' ~ htmlLocale ~ '.html.twig' with {'title' : resource.title } %}
Run Code Online (Sandbox Code Playgroud)
虽然这有效,但如果所选的区域设置尚未(部分)创建其部分,则存在风险,这将引发错误.我想要做的是在尝试渲染之前检查partial的存在,如果它还不存在则回退到默认值.
{% if '@BundleName/Layout/Text/_partial-name.' ~ htmlLocale ~ '.html.twig' %}
{% include '@BundleName/Layout/Text/_partial-name.' ~ htmlLocale ~ '.html.twig' with {'title' : resource.title } %}
{% else %}
{% include '@BundleName/Layout/Text/_partial-name.html.twig' with {'title' : resource.title } %}
{% endif %}
Run Code Online (Sandbox Code Playgroud)
显然这不起作用,但这就是我追求的那种东西!
我有一个很大的表格,其中的字段是基于模式动态绘制的。(我正在遍历JSON模式以写入我的字段)。
我的某些字段是嵌套的,因此命名约定遵循点符号。
ParentField.ChildField.Name
Run Code Online (Sandbox Code Playgroud)
这将自动嵌套数据作为输入。
ParentField {
ChildField {
Name: "Value of field"
}
}
Run Code Online (Sandbox Code Playgroud)
redux-form提供了一个FieldArray,允许您push()按需字段,但这改变了数据格式以包括信息数组- 不是我想要的!
因此,我需要能够按需注册和注销字段(例如,单击按钮)
这些文档指向actionCreators,但我不知道如何实现它们。
javascript ×2
laravel ×2
laravel-5 ×2
react-native ×2
blade ×1
expo ×1
meta ×1
mobile ×1
php ×1
react-redux ×1
reactjs ×1
redux-form ×1
symfony ×1
twig ×1