laravel

How to use 'where' on column with comma separated values in laravel

倖福魔咒の 提交于 2021-02-18 11:20:07
问题 I am using php with laravel framework. I want to get rows from table that contains user id. Problem here is that user id is integer value and column(author) contain more than one comma separated integer values. Here is example. DB::table('stories')->where('author','4')->get(); author column have values : row 1: 2,4,5 | row 2: 1,3,14 | row 3 : 4,5 and I will get row 1 and 3. So, Please help me to get right rows. 回答1: You can use whereRaw like as DB::table('stories')->whereRaw("find_in_set('4'

Laravel Model Factory without connection to database

感情迁移 提交于 2021-02-18 10:12:23
问题 I would like to use Laravel's Model Factory in some PHPUnit tests. The only thing I want to do is make a Model instance without saving it to database. Why the Model Factory needs connection to database? These tests must pass on CI environment without configured database. When I create Model manually by new App\Model($dataArray) , tests pass and the connection is not needed. I am using Model Factory in other places, so I would like to reuse it in that tests, to avoid code duplication. I am

Laravel Model Factory without connection to database

為{幸葍}努か 提交于 2021-02-18 10:10:34
问题 I would like to use Laravel's Model Factory in some PHPUnit tests. The only thing I want to do is make a Model instance without saving it to database. Why the Model Factory needs connection to database? These tests must pass on CI environment without configured database. When I create Model manually by new App\Model($dataArray) , tests pass and the connection is not needed. I am using Model Factory in other places, so I would like to reuse it in that tests, to avoid code duplication. I am

Laravel : advanced search form query

杀马特。学长 韩版系。学妹 提交于 2021-02-18 08:35:54
问题 I have an advanced search form to filter out results from a database using Laravel. The data is filtered correctly but I have a requirement for the user to be able to filter by first name or last name using the same text box (in the advanced form). I tried orWhere to make sure it filters the name field with the first name or last name but the orWhere doesn't consider the other filters. The code I am using is as follows: DB::table('mytable') ->where(function($query) use ($name, $degree_s,

Laravel : advanced search form query

限于喜欢 提交于 2021-02-18 08:35:32
问题 I have an advanced search form to filter out results from a database using Laravel. The data is filtered correctly but I have a requirement for the user to be able to filter by first name or last name using the same text box (in the advanced form). I tried orWhere to make sure it filters the name field with the first name or last name but the orWhere doesn't consider the other filters. The code I am using is as follows: DB::table('mytable') ->where(function($query) use ($name, $degree_s,

How would you organize mails in a multilingual Laravel application

こ雲淡風輕ζ 提交于 2021-02-18 08:03:00
问题 I'm curious about how to effectively generate emails in a multilingual application. For the sake of getting all answers aligned: let's say you have a typical commercial newsletter with lots of images, markup, and of course many textual paragraphs. Assume that all text does NOT come from a database but should be hard-coded. Moreover, some words in these paragraphs can be bolded, emphasized,... The newsletter will be sent in the subscriber's preferred locale. How can I build a system to handle

How would you organize mails in a multilingual Laravel application

只愿长相守 提交于 2021-02-18 08:02:38
问题 I'm curious about how to effectively generate emails in a multilingual application. For the sake of getting all answers aligned: let's say you have a typical commercial newsletter with lots of images, markup, and of course many textual paragraphs. Assume that all text does NOT come from a database but should be hard-coded. Moreover, some words in these paragraphs can be bolded, emphasized,... The newsletter will be sent in the subscriber's preferred locale. How can I build a system to handle

php 关于laravel5.7框架

荒凉一梦 提交于 2021-02-18 07:36:57
一、配置 首先说下配置,安装 node.js 、npm 。cmd 命令行 node -v 、npm -v 若已安装出现版本号,若无自行百度 安装 compaser 通过compaser命令安装laravel 到指定目录 配置成功后如下图: 二、框架模型 laravel 也是基于 MVC 模式, model -> view -> controller 。如若写接口则是 model -> logic(逻辑层) -> controller ,再加前端 vue 完美。 先说说laravel 的优点 :其一 因为本身框架基于php ,所以支持php很多特性,其二 是代码本身比较简洁,其三 开发效率快 下图是laravel安装成功后的文件,这里我的开发工具是 phpstorm 三、语法要点 这里要讲比较重要,都是踩过的坑 第一讲讲laravel 的命名空间问题 写法 namespace App\Http\Logic 注意下划线 \ 引用类则是 use 这里有个关于DB 的引用,可能你未引用 Illuminate\Support\Facades\DB 也能点出 DB 但会报错 继承 extends 这里要写好你的json公共继承类 结构 这里和C# 类的实例化有点相似 方法 public function __construct() 例: $this -> model=new Student()

React js - Laravel 5: Using csrf-token in POST method

為{幸葍}努か 提交于 2021-02-18 07:23:26
问题 I've read some questions about Laravel's CSRF, but I still haven't found how to use it with React. My goal is to make a POST form, where I make an AJAX call. Here is an extract of my render( ) . render() { return ( <form method="post" action="logpage"> <input type="hidden" name="csrf-token" value="{{{ csrf_token() }}}" /> //I'm sure this doesn't have csrf_token. <input type="text" name ="word" value={this.state.word || ''}/> <button onClick={this.submit} className="btn btn-flat btn-brand

Call Mongodb stored function from PHP7

倖福魔咒の 提交于 2021-02-18 03:19:58
问题 Below is my mongodb function that is stored in Mongodb. db.system.js.save( { _id: "echoFunction", value : function(x) { return x; } } ) I can call this function in mongo using below query : db.loadServerScripts(); echoFunction(3); Now i want to call this function from PHP 7. and also help with laravel. 回答1: You can use following code snippet from laravel to execute your mongoDB function. $cursor = DB::connection('mongodb')->command(array('eval' => 'echoFunction("4")')); $data = $cursor-