产品具有一对多的关系,'productbrand',表productbrand和productbrand具有一对一的关系,'品牌',与表品牌.表品牌有一个专栏,'品牌'.我可以访问该产品的品牌.可以正确访问所有其他类别,用户名等.
public function show(Request $request)
{
if($request->ajax())
{
$id = $request->id;
if($id)
{
$show = Product::where(['product_id'=>$id])->first();
$category = $show->category->category;
$username = $show->user->username;
$getbrands = $show->productbrand;
foreach($getbrands as $getbrand)
{
$brand=$getbrand->brand->brand;
}
if($show)
{
echo json_encode(array('status' => TRUE, 'show' => $show, 'username' => $username, 'category' => $category, 'brand' => $brand)); die;
}
}
}
echo json_encode(FALSE);die;
}
Run Code Online (Sandbox Code Playgroud)
Ajax和jQuery:
$.ajax({
type: "POST",
url: "{{url('/product/show')}}",
data: {id:id},
success: function (data) {
var res = $.parseJSON(data);
if(res.status == true)
{
var result = 'Category: …Run Code Online (Sandbox Code Playgroud) 在 WordPress 中创建块时,我需要添加带有链接的翻译。我在 JS 中这样做,但它没有提供预期的结果:
import { render } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
export default function Final() {
let d = <a href="https://example.com">bothered me.</a>;
return (
<p> { __( 'The cold never {d} anyway.', 'text-domain' ) } </p>
)
}
document.addEventListener( "DOMContentLoaded", function(event) {
const appRoot = document.getElementById( 'root' );
if ( appRoot ) {
render(
<Final/>,
appRoot
)
}
});
Run Code Online (Sandbox Code Playgroud)
在 PHP 中,我可以使用 sprintf 并使用 %1s 等占位符轻松做到这一点。
echo sprintf(
__( 'The cold never %1s anyway', …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个基本的测验系统.下面的代码显示了用户如何使用radio butto选择答案,getresult.php将无线电输入值与答案列进行比较.在我的数据库中有一个问题,opt1,opt2,opt3,opt4和答案列.
<form method="POST" action="getresult.php">
<label>Enter Your Name:</label><br>
<input type="text" name="name"><br><br>
<?php
$db = new mysqli("localhost", "root", "","learndb");
$stmt=$db->prepare("SELECT * FROM quiz");
$stmt->execute();
$result=$stmt->get_result();
echo "<form method='POST' action='getresult.php'>";
while($myrow = $result->fetch_assoc())
{
echo $myrow['id'];
echo ".";
echo $myrow['question'];
echo "<br>";
echo "<input type='radio' name='mycheck[".$myrow['id']."]' value=".$myrow['opt1'].">";
echo $myrow['opt1'];
echo "<br>";
echo "<input type='radio' name='mycheck[".$myrow['id']."]' value=".$myrow['opt2'].">";
echo $myrow['opt2'];
echo "<br>";
echo "<input type='radio' name='mycheck[".$myrow['id']."]' value=".$myrow['opt3'].">";
echo $myrow['opt3'];
echo "<br>";
echo "<input type='radio' name='mycheck[".$myrow['id']."]' value=".$myrow['opt4'].">";
echo $myrow['opt4'];
echo "<br><br>";
}?>
<input type="submit" name="submit" …Run Code Online (Sandbox Code Playgroud) 我有这种类型的HTML:
<p id="username_input" data-priority="">
<label for="username">Username</label>
<input type="text" class="input-text um-field " name="username" id="username" placeholder="" value="" required="required" data-label="Username">
</p>
<p id="firstname_input" data-priority="">
<label for="firstname">First Name</label>
<input type="text" class="input-text um-field " name="firstname" id="firstname" placeholder="" value="" required="required" data-label="FirstName">
</p>
<p class="form-row " id="radio_SXsPOwVSD_input">
<input type="radio" class="input-radio um-field" value="Male" name="radio_SXsPOwVSD" id="radio_SXsPOwVSD_male">Male
<input type="radio" class="input-radio um-field" value="Female" name="radio_SXsPOwVSD" id="radio_SXsPOwVSD_Female">Female
</p>
Run Code Online (Sandbox Code Playgroud)
applyConditions数组包含input,condition和value索引.可以是任何输入,也可以是许多条件.假设,
input = username
condition = 0 (is)
value = abc
input = firstname
condition = 1 (is …Run Code Online (Sandbox Code Playgroud) 我正在使用laravel手动身份验证系统.提交表单重定向到下面显示的此路由.并且在authenticate()函数中,名称和密码永远不会匹配我之前存储的.即Auth::attempt总是假的.
Route::post('/logintest', 'mycontroller@authenticate');
Route::get('/home', ['middleware' => 'auth', function() {
echo "home page";});
}]);
Run Code Online (Sandbox Code Playgroud)
验证功能:
public function authenticate(Request $request)
{
$input=$request->all();
$password=$input['password'];
$name=$input['name'];
if (Auth::attempt(['Name' => $name, 'Password' => $password]) ){
return redirect()->intended('/home');
} else
{
return redirect('/login')->with('message','Error logging in!');
}
}
Run Code Online (Sandbox Code Playgroud)
我以这种方式注册了用户.使用bcrypt()对密码进行哈希处理.功能.但在authenticate()函数中,我正在与普通密码进行比较.我在哪里阅读Auth自动处理它.或者我是否应该在config/auth.php中更改某些内容,因为我使用了名称来验证而不是用户名?
public function register(Request $request)
{
$input=$request->all();
$password=bcrypt($input['password']);
$name=$input['name'];
$insert= User::insert(['Name'=>$name,'Password'=>$password]);
return redirect('/login')
->with('message','successfully Registered.');
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试获取过去 48 小时内至少有 2 条评论的所有帖子。我正在使用以下代码:
$posts= Post::has( 'comments', '>', 1 )->whereHas( 'comments', function( $comments ) {
return $comments->where( 'created_at', '>', Carbon::now()->subDays(2) );
})->get()->toArray();
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用变量检索刀片模板中的序列号i:
<?php $i=0;?>
@foreach ($lists as $li)
<tr><td><?php $i++;?>{{$i}}</td><td>{{$li->Name}}</td><td>{{$li->Telephone}}
</td><td>{{$li->mobile}}</td>
@endforeach
{!! $lists->render() !!}
Run Code Online (Sandbox Code Playgroud)
但我在控制器中使用分页:
$lists=telephone::orderBy('name')->simplePaginate(10);
Run Code Online (Sandbox Code Playgroud)
所以,第一页的序列号是可以的。但是对于第二页i再次从 1 开始。
我有三个不同大小的设备的这三个CSS链接.
<link href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/maxwidth959.css" rel='stylesheet'>
<link href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/maxwidth768.css" rel='stylesheet'>
<link href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/maxwidth600.css" rel='stylesheet'>
Run Code Online (Sandbox Code Playgroud)
媒体查询所有人:
maxwidth959.css
@media only screen and (max-width: 959px)
{
// styles here
}
Run Code Online (Sandbox Code Playgroud)
maxwidth768.css
@media only screen and (max-width: 768px)
{
// styles here
}
Run Code Online (Sandbox Code Playgroud)
maxwidth600.css
@media only screen and (max-width: 600px)
{
// styles here
}
Run Code Online (Sandbox Code Playgroud)
但只有最后一个链接的CSS(maxwidth600.css)CSS正在生效,其他人是否重写?