小编byt*_*ker的帖子

在Laravel 5.2中从数据库中删除列

我有一个博客,其articles表格Schema定义如下:

public function up()
{
    Schema::create('articles', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id')->unsigned();
        $table->string('title');
        $table->string('thumb')->nullable();
        $table->text('excerpt');
        $table->text('body');
        $table->string('slug')->unique();
        $table->integer('comment_count')->unsigned()->default(0);
        $table->integer('view_count')->unsigned()->default(0);
        $table->timestamps();
        $table->softDeletes();
}

public function down()
{
    Schema::drop('articles');
}
Run Code Online (Sandbox Code Playgroud)

我想删除列comment_count,view_count而不会丢失表中的现有数据

我定义了一个像这样的新迁移:

class RemoveCommentViewCount extends Migration
{
    public function up()
    {
        //nothing here
    }

    public function down()
    {
        Schema::table('articles', function($table) {
           $table->dropColumn('comment_count');
           $table->dropColumn('view_count');
       });
   }
}
Run Code Online (Sandbox Code Playgroud)

而且我做到了php artisan migrate.它确实成功迁移,但两列并未删除.

我究竟做错了什么?如何在不丢失表中现有数据的情况下删除这些列?

laravel laravel-5.2

40
推荐指数
3
解决办法
5万
查看次数

Laravel 5.4中的自定义帮助程序类

我有一些辅助课程app/Helpers.如何使用a加载这些类service provider以在刀片模板中使用它们?

例如,如果我有一个CustomHelper包含方法的类fooBar():

<?php

nampespace App\Helpers;

class CustomHelper
{
    static function fooBar()
    {
        return 'it works!';
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望能够在我的刀片模板中执行以下操作:

{{ fooBar() }}
Run Code Online (Sandbox Code Playgroud)

而不是这样做:

{{ \App\Helpers\CustomHelper::fooBar() }}
Run Code Online (Sandbox Code Playgroud)

PS: @安德鲁-布朗的回答的最佳做法上Laravel 5个自定义的助手与非类文件的交易.拥有一个基于类的解决方案会很好,这样可以在类之间组织辅助函数.

php laravel composer-php laravel-5 laravel-5.4

14
推荐指数
1
解决办法
1万
查看次数

使用 pipe() 和 fork() 复制文件内容

已经有人问过类似的问题,但他们的解决方案对我帮助不大

读取文件并使用管道将其发送到父进程的程序

在管道上读/写,在C中完成文件复制


我正在尝试从文件test.txt(包含单行文本)读取,将其写入管道,子进程将从该管道读取并将内容写入另一个文件。

 /* Read the contents of a file and display it using pipe */

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

void main()
{
  char buffer[100];
  char childbuff[100];
  int fd[2], des, bytes, target;

  pipe(fd);

  if(fork()) {
    /* parent process closes the downstream */
    close(fd[0]);

    /* reads the file */
    des = open("test.txt", O_RDONLY);
    bytes = read(des, buffer, sizeof(buffer));

    /* puts data in pipe */
    write(fd[1], buffer, bytes);
  } else {
    /* Child …
Run Code Online (Sandbox Code Playgroud)

c linux

6
推荐指数
1
解决办法
5920
查看次数

Laravel 5.2 - 未显示验证错误

我正在尝试验证Laravel 5.2中的登录/注册系统.

我正在使用welcome.blade.php索引页面,其中包含两个表单,用于注册和登录

这是我UserController.php的设置方式:

namespace authme\Http\Controllers;

use Illuminate\Http\Request;
use authme\User;
use Illuminate\Support\Facades\Auth;

class UserController extends Controller
{
    public function getDashboard()
    {
        return view('dashboard');
    }
    public function doSignUp(Request $request)
    {
        $this->validate($request, [
            'email' => 'required|email|unique:users',
            'first_name' => 'required|max:120',
            'password' => 'required|min:6'
        ]);

        $email = $request['email'];
        $password = bcrypt($request['password']);
        $first_name = $request['first_name'];
        $last_name = $request['last_name'];
        $location = $request['location'];
        $phone = $request['phone'];

        $user = new User();
        $user->email = $email;
        $user->password = $password;
        $user->firstname = $first_name;
        $user->lastname = $last_name;
        $user->location …
Run Code Online (Sandbox Code Playgroud)

php validation laravel blade

3
推荐指数
1
解决办法
784
查看次数