我有一个表格,用户可以填写出售他们的家.对于其中一个投注,用户必须选择天气,它将是"待售"或"出租".如果是For Sale,则会出现两个价格输入字段,如果是For Rent,那么其他一些价格输入字段将基于jQuery显示.
我的问题是我想要价格字段是必需的,但是例如如果我选择"出租",然后我提交我的表格,它会给我一个错误说"待售"输入字段的价格字段是必需的,即使它是在"出租"部分.
我知道Laravel中有一个required_if,但我不知道如何利用它.这是我对物业的要求.
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class PropertyRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'list_type' => 'required',
'sale_price' => 'required', // <-- maybe like: required_if:value
'rent_price' => 'required',
];
}
} …Run Code Online (Sandbox Code Playgroud) 我是Traits的新手,但是我的函数中有很多重复的代码,我想使用Traits来减少代码的混乱.我Traits在我的Http目录中创建了一个名为Trait的目录BrandsTrait.php.它所做的只是呼吁所有品牌.但是当我尝试在我的产品控制器中调用BrandsTrait时,如下所示:
use App\Http\Traits\BrandsTrait;
class ProductsController extends Controller {
use BrandsTrait;
public function addProduct() {
//$brands = Brand::all();
$brands = $this->BrandsTrait();
return view('admin.product.add', compact('brands'));
}
}
Run Code Online (Sandbox Code Playgroud)
它给我一个错误,说方法[BrandsTrait]不存在.我想初始化一些东西,或者用不同的方式称呼它?
这是我的 BrandsTrait.php
<?php
namespace App\Http\Traits;
use App\Brand;
trait BrandsTrait {
public function brandsAll() {
// Get all the brands from the Brands Table.
Brand::all();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将Beautymail用于我的项目,以便在客户订购东西后发送收据。问题是我在功能中使用Beautymail的方式不像其文档说明状态那样。
这就是我在函数中使用它的方式:
class OrderController extends Controller {
public function postOrder(Request $request) {
// More stuff here, shortned for question purposes
// Get an instance of the currently authenticated user
$user = Auth::user();
// Send email conformation to user that just bought a product or products.
$beautymail = app()->make(Snowfire\Beautymail\Beautymail::class);
$beautymail->send('emails.welcome', [], function($message) {
$message
->from('example@admin.com')
->to($user->email, $user->username)
->subject('Your Receipt');
});
// Then return redirect back with success message
flash()->success('Success', 'Your order was processed successfully. A receipt has been emailed …Run Code Online (Sandbox Code Playgroud) 我正在尝试进行查询,在其中可以找到 SQL 数据库中给定经度和纬度点(比方说 50 英里)内的所有位置。
我填充了一些帖子,在帖子表中我有两列,用于在创建帖子时存储经度和纬度。该表的外观如下:
我浏览了许多如何尝试实现这一点的示例,但似乎它们不起作用。通过研究我知道 ASP.NET Core 不支持DbGeography,其他文章也已经过时了。
找到这篇文章,但它使用了DbGeography,所以不起作用。
在 GitHub 上找到了这个:我只是不知道这是否可行。
仅供参考,这就是我的 Post 模型的外观:
public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public double Lat { get; set; }
public double Lng { get; set; }
public DateTime Created { get; set; }
public Category Category { get; set; }
public int CategoryId { get; set; }
// Other …Run Code Online (Sandbox Code Playgroud) 我正在研究Halo 5 API.我申请获得更高的API速率限制,我得到的答案之一是:
您能否向我们提供有关您对API进行哪些调用以及是否使用任何缓存的更多详细信息?具体来说,我们建议缓存匹配和事件详细信息和元数据,因为这些很少更改.
当他们说"哪个叫你正在制作"时,我得到了这个部分,但是缓存部分,我从来没有使用过.我得到了缓存的基本部分,它加速了你的API,但我不知道如何将它实现到我的API中.
我想知道如何在我的应用程序中缓存一些数据.这是我如何通过API获得玩家奖牌的基本示例.
路线:
Route::group(['middleware' => ['web']], function () {
/** Get the Home Page **/
Route::get('/', 'HomeController@index');
/** Loads ALL the player stats, (including Medals, for this example) **/
Route::post('/Player/Stats', [
'as' => 'player-stats',
'uses' => 'StatsController@index'
]);
});
Run Code Online (Sandbox Code Playgroud)
我的GetDataController调用API Header获取玩家奖牌:
<?php
namespace App\Http\Controllers\GetData;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
use GuzzleHttp;
use App\Http\Controllers\Controller;
class GetDataController extends Controller {
/**
* Fetch a Players Arena Stats
*
* @param $gamertag
* @return mixed
*/
public function …Run Code Online (Sandbox Code Playgroud) 我刚刚为 Laravel 下载了这个包。
它是一个 Google Anayltics 软件包,我遵循了设置帐户的所有步骤。我遇到的问题是调用方法。例如,当它说:
以下是检索当天和过去 7 天的访问者和综合浏览量数据的示例。
$analyticsData = Analytics::fetchVisitorsAndPageViews(Period::days(7));
Run Code Online (Sandbox Code Playgroud)
我尝试在我的函数中这样做:
<?php
namespace App\Http\Controllers\Admin;
use Carbon\Carbon;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Spatie\Analytics\Analytics;
use Illuminate\Support\Collection;
class DashboardController extends Controller {
public function index() {
$analytics = Analytics::fetchVisitorsAndPageViews(Period::days(7));
dd($analytics);
return view('admin.dashboard-v2');
}
}
Run Code Online (Sandbox Code Playgroud)
它给了我这样的错误:
非静态方法 Spatie\Analytics\Analytics::fetchVisitorsAndPageViews() 不应静态调用
我在这里错过了什么吗?除了 Github 自述文件之外,我在网上找不到任何特定的文档
我正在调用 Halo 5 API,特别是获取竞技场中每个玩家使用的武器。我遇到的问题是,当我拨打电话时,有 7 种武器被玩家击杀 0 次,如下所示:
\n\n18 => array:3 [\xe2\x96\xbc\n "WeaponId" => 2457457776.0\n "TotalKills" => 0\n "TotalHeadshots" => 0\n ]\n 53 => array:3 [\xe2\x96\xbc\n "WeaponId" => 2015271382\n "TotalKills" => 0\n "TotalHeadshots" => 0\n ]\n 51 => array:3 [\xe2\x96\xb6]\n 48 => array:3 [\xe2\x96\xb6]\n 44 => array:3 [\xe2\x96\xb6]\n 27 => array:3 [\xe2\x96\xb6]\n 32 => array:3 [\xe2\x96\xb6]\nRun Code Online (Sandbox Code Playgroud)\n\n我想把这 7 件武器从我的收藏中拿出来:
\n\n这就是我的收藏的设置方式:
\n\n public function getArenaWeaponKills($playerArenaWeaponStats) {\n\n $results = collect($playerArenaWeaponStats->Results[0]->Result->ArenaStats->WeaponStats);\n\n $array = $results->sortByDesc(\'TotalKills\')->map(function($item, $key) {\n return [\n \'WeaponId\' => …Run Code Online (Sandbox Code Playgroud) laravel ×6
php ×6
laravel-5.2 ×4
json ×2
asp.net ×1
c# ×1
caching ×1
collections ×1
email ×1
geocoding ×1
laravel-5 ×1
traits ×1
validation ×1